LoginSignup
1
2

More than 5 years have passed since last update.

XCPlaygroundを試してみる

Posted at

数値をちょっと変えてみたい時とかにいいですね

スクリーンショット 2016-03-31 00.22.21.png

import UIKit
import XCPlayground

let view = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 200, height: 200))
XCPlaygroundPage.currentPage.liveView = view


class customLayer : CAShapeLayer {

    override init() {
        super.init()
    }

    override init(layer: AnyObject) {
        if let layer = layer as? customLayer {
        }
        super.init(layer: layer)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func drawInContext(ctx: CGContext) {
        //背景
        let c = UIColor.whiteColor()
        CGContextSetFillColorWithColor(ctx, c.CGColor)
        CGContextAddRect(ctx, self.bounds)
        CGContextDrawPath(ctx, .Fill)


        for(var i : CGFloat = 0;i<360;i+=1){
            let cc = UIColor(hue: i/360, saturation: 1.0, brightness: 1.0, alpha: 1.0)
            CGContextMoveToPoint(ctx, 100, 100)
            let sa : CGFloat = i * CGFloat(M_PI/180)
            let ea : CGFloat = ((i + 1) * CGFloat(M_PI/180))

            CGContextAddArc(ctx, 100, 100, 100, sa, ea, 0)
            CGContextClosePath(ctx)
            CGContextSetFillColorWithColor(ctx, cc.CGColor)
            CGContextDrawPath(ctx, .Fill)

        }
    }
}


let c = customLayer()
c.frame = view.frame
view.backgroundColor = UIColor.blueColor()
view.layer.addSublayer(c)
c.setNeedsDisplay()

参考

UIBezierPath with color gradient

XcodeのPlaygroundをつかってUIの実装をサクサク試す

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2