如何仅将角半径设置为仅左下角,右下角和左上角textview?
let rectShape = CAShapeLayer() rectShape.backgroundColor = UIColor.redColor().CGColor rectShape.bounds = messages.frame rectShape.position = messages.center rectShape.path = UIBezierPath(roundedRect: messages.bounds, byRoundingCorners: .BottomLeft | .TopRight, cornerRadii: CGSize(width: 20, height: 20)).CGPath messages.layer.addSublayer(rectShape)
此代码创建两个矩形。我不知道为什么。
您只需要遮罩该图层,如下所示:
对于Swift 3 :
let rectShape = CAShapeLayer() rectShape.bounds = self.myView.frame rectShape.position = self.myView.center rectShape.path = UIBezierPath(roundedRect: self.myView.bounds, byRoundingCorners: [.bottomLeft , .bottomRight , .topLeft], cornerRadii: CGSize(width: 20, height: 20)).cgPath self.myView.layer.backgroundColor = UIColor.green.cgColor //Here I'm masking the textView's layer with rectShape layer self.myView.layer.mask = rectShape
较低版本:
let rectShape = CAShapeLayer() rectShape.bounds = self.myView.frame rectShape.position = self.myView.center rectShape.path = UIBezierPath(roundedRect: self.myView.bounds, byRoundingCorners: .BottomLeft | .BottomRight | .TopLeft, cornerRadii: CGSize(width: 20, height: 20)).CGPath self.myView.layer.backgroundColor = UIColor.greenColor().CGColor //Here I'm masking the textView's layer with rectShape layer self.myView.layer.mask = rectShape