0
我有具體UIBezierPath
,例如由Y切割的貝塞爾路徑協調
override func drawInContext(ctx: CGContext) {
if let slider = slider {
// Clip
let rect = bounds.insetBy(dx: bounds.width/10, dy: bounds.height/2.2)
let path = UIBezierPath(roundedRect: rect, cornerRadius: 5)
let circleRadius : CGFloat = 10
let xCoordInset = bounds.width/10
let circlePath = UIBezierPath(ovalInRect: CGRectMake(xCoordInset , rect.midY - circleRadius, circleRadius * 2, circleRadius * 2))
let circlePath1 = UIBezierPath(ovalInRect: CGRectMake(bounds.width - xCoordInset - circleRadius, rect.midY - circleRadius, circleRadius * 2, circleRadius * 2))
let circlePath2 = UIBezierPath(ovalInRect: CGRectMake(rect.midX - circleRadius, rect.midY - circleRadius, circleRadius * 2, circleRadius * 2))
path.appendPath(circlePath)
path.appendPath(circlePath1)
path.appendPath(circlePath2)
CGContextAddPath(ctx, path.CGPath)
CGContextSetFillColorWithColor(ctx, slider.trackTintColor.CGColor)
CGContextFillPath(ctx)
}
}
我想填補這一bezierPath與灰顏色的一半,另一半用紅色。所以我想我需要有2個相同的圖層,但是其中的1個應該用y座標來剪切,你能爲這個動作提供一些可用的方法嗎?
你可以創建兩個相同的形狀,並應用其中一個面具 –