项目中用到只设置label的左下角和右下角为圆角,用UIBezierPath实现,记录一下。
let corner = UIRectCorner(rawValue: UIRectCorner.bottomLeft.rawValue | UIRectCorner.bottomRight.rawValue)
let maskPath = UIBezierPath(roundedRect: label.bounds, byRoundingCorners: corner, cornerRadii: CGSize(width: 4, height: 4))
let maskLayer = CAShapeLayer()
maskLayer.frame = label.bounds
maskLayer.path = maskPath.cgPath
label.layer.mask = maskLayer
其中,corner是设置具体哪个角为圆角 :UIRectCorner.bottomLeft, UIRectCorner.bottomRight, UIRectCorner.topLeft,UIRectCorner.topRight
let corner = UIRectCorner(rawValue: UIRectCorner.bottomLeft.rawValue | UIRectCorner.bottomRight.rawValue)
以下为实现效果图