【发布时间】:2016-05-05 19:27:21
【问题描述】:
我使用 UIBezierPath 逐点添加创建了一个矩形,现在我想圆角这个矩形的角,但似乎没有办法做到这一点。谁能帮帮我?
class RectangleLayer: CAShapeLayer {
let animationDuration: CFTimeInterval = 0.5
override init() {
super.init()
fillColor = Colors.clear.CGColor
lineWidth = 5.0
path = rectanglePathStart.CGPath
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
var rectanglePathStart: UIBezierPath {
let rectanglePath = UIBezierPath()
rectanglePath.moveToPoint(CGPoint(x: 0.0, y: 100.0))
rectanglePath.addLineToPoint(CGPoint(x: 0.0, y: -lineWidth))
rectanglePath.addLineToPoint(CGPoint(x: 100.0, y: -lineWidth))
rectanglePath.addLineToPoint(CGPoint(x: 100.0, y: 100.0))
rectanglePath.addLineToPoint(CGPoint(x: -lineWidth / 2, y: 100.0))
rectanglePath.closePath()
// fillColor = Colors.red.CGColor
return rectanglePath
}
}
【问题讨论】:
-
你可以使用
bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise:来圆每个角。
标签: swift calayer uibezierpath rounded-corners cashapelayer