如何只为左下角,右下角和左上角的textview设置cornerRadius?

如何仅将角半径设置为仅左下角,右下角和左上角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)

此代码创建两个矩形。我不知道为什么。

回答:

您只需要遮罩该图层,如下所示:

    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

以上是 如何只为左下角,右下角和左上角的textview设置cornerRadius? 的全部内容, 来源链接: utcz.com/qa/417936.html

回到顶部