我需要创建一个自定义类才能在Swift playgrounds中使用BezierPath吗?
以下代码什么也不显示,只有黑色背景:
import UIKit
import XCPlayground
class GraphView : UIView {
override func drawRect(rect: CGRect) {
let path = UIBezierPath(rect: rect)
path.moveToPoint(CGPointMake(0,0))
path.addLineToPoint(CGPointMake(50,100))
path.closePath()
UIColor.redColor().setFill()
path.stroke()
}
}
let graphView = GraphView(frame: CGRectMake(0,0,960,640))
stroke
。如果你想绘制描边,请调用UIColor.redColor().setStroke()
。如果你想要填充颜色,使用UIColor.redColor().setFill()
并调用fill
而不是stroke
。 - Rob