我只想把图像的两个底角围起来。
我在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'
最佳答案
我们把这样的东西放在快速变化的方式。在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