如何为UIBezier路径的内部着色?我正在制作一个简单的三角形,并想用红色在三角形内部进行着色。在Swift中归档UIBezierPath
class GraphView : UIView {
override func drawRect(rect: CGRect) {
UIColor.redColor().setFill()
UIColor.greenColor().setStroke()
let path = UIBezierPath(rect: rect)
path.moveToPoint(CGPointMake(100,620))
path.addLineToPoint(CGPointMake(300,100))
path.addLineToPoint(CGPointMake(500,620))
path.addLineToPoint(CGPointMake(100,620))
path.closePath()
path.fill()
path.stroke()
}
}
let graphView = GraphView(frame: CGRectMake(0,0,960,640))
XCPlaygroundPage.currentPage.liveView = graphView
上面的代码写在操场:下面是结果:
奥普抱歉!用代码和新屏幕截图更新了问题。 –