how to set cornerRadius for only bottom-left,bottom-right and top-left corner textview?

前端 未结 12 873
名媛妹妹
名媛妹妹 2020-11-27 12:50

How to set corner radius only only bottom-left,bottom-right and top-left corner textview?

let rectShape = CAShapeLayer()
    rectShape.backgroundColor = UICo         


        
12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 13:20

    Swift 3

    extension UIView {
        func roundCorners(_ corners:UIRectCorner, radius: CGFloat) {
        let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
        let mask = CAShapeLayer()
        mask.path = path.cgPath
        self.layer.mask = mask
      }
    }
    

    Use like this

    YourView.roundCorners([.topLeft, .bottomLeft], radius: 10)
    

提交回复
热议问题