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

前端 未结 12 918
名媛妹妹
名媛妹妹 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:17

    Swift 4+

    func roundCorners(with CACornerMask: CACornerMask, radius: CGFloat) {
              self.layer.cornerRadius = radius
              self.layer.maskedCorners = [CACornerMask]
        }
    

    Top right

    roundCorners(with: [.layerMinXMinYCorner], radius: 20)
    

    Top left

    roundCorners(with: [.layerMaxXMinYCorner], radius: 20)
    

    Bottom right

    roundCorners(with: [.layerMinXMaxYCorner], radius: 20)
    

    Bottom left

    roundCorners(with: [.layerMaxXMaxYCorner], radius: 20)
    

    OR

    Multiple corners at the same time

        func roundedCorners(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
            layer.mask = mask
        }
    

    How to use

    roundedCorners(corners: [.topLeft, .topRight], radius: 20)
    

提交回复
热议问题