iOS-swift3.0 点滴积累:设置控件指定角为圆角
2017-07-07 本文已影响0人
xiaopavip
项目中用到只设置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)
以下为实现效果图
WechatIMG10.jpeg