我想只围绕图像的两个底角。 我在Objective-C中发现了很多例子,而Swift几乎没有。
这是我发现的,但它给了我一个错误:
let rectShape = CAShapeLayer()
rectShape.bounds = self.image.frame
rectShape.position = self.image.center
rectShape.path = UIBezierPath(roundedRect: self.image.bounds, byRoundingCorners: .BottomLeft | .BottomRight, cornerRadii: CGSize(width: 20, height: 20)).CGPath
self.image.layer.backgroundColor = UIColor.greenColor().CGColor
self.image.layer.mask = rectShape
我得到的错误与rectShape.path
一致,告诉我
No '|' candidates produce the expected contextual result type 'UIRectCorner'
答案 0 :(得分:3)
迅速改变我们这样做的方式。在目标c中,可以写一个|分开选项,但在swift中你必须把它像一个数组:
let rectShape = CAShapeLayer()
rectShape.bounds = self.image.frame
rectShape.position = self.image.center
rectShape.path = UIBezierPath(roundedRect: self.image.bounds, byRoundingCorners: [.BottomLeft, .BottomRight], cornerRadii: CGSize(width: 20, height: 20)).CGPath
self.image.layer.backgroundColor = UIColor.greenColor().CGColor
self.image.layer.mask = rectShape
答案 1 :(得分:0)
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [.TopLeft, .BottomLeft], cornerRadii: CGSize(width: 3, height: 3 ))