【发布时间】:2016-03-01 13:58:43
【问题描述】:
我正在尝试在 drawRect 方法中实现透明路径。这是我创建的简单代码:
override func drawRect(rect: CGRect) {
let clippingPath = UIBezierPath()
UIColor.whiteColor().set();
clippingPath.moveToPoint(CGPoint(x: 10, y: CGRectGetHeight(self.bounds) / 2))
clippingPath.addLineToPoint(CGPoint(x: CGRectGetWidth(self.bounds) - 10, y: CGRectGetHeight(self.bounds) / 2))
clippingPath.lineWidth = 6
clippingPath.lineCapStyle = .Round
clippingPath.stroke()
}
结果如下:
有没有办法让背景保持实心但路径线透明。如果我将第二行更改为 UIColor.clearColor().set() 似乎什么也没发生,我只会得到一个完整的纯色背景色(在这种情况下为黑色。
【问题讨论】:
标签: ios core-graphics drawrect uibezierpath