如何爲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
上面的代碼寫在操場:下面是結果:
奧普抱歉!用代碼和新屏幕截圖更新了問題。 –