<code>//有离屏渲染</code>
let button = UIButton(frame: CGRect(x: 100, y: 100, width: 60, height: 50))
button.backgroundColor = UIColor.brown
button.setTitle("test", for: .normal)
view.addSubview(button)
let bezierPath = UIBezierPath(roundedRect: button.bounds,
byRoundingCorners: [.allCorners], //哪个角
cornerRadii: CGSize(width: 5, height: 5)) //圆角半径
let maskLayer = CAShapeLayer()
maskLayer.path = bezierPath.cgPath
button.layer.mask = maskLayer;
<code>//如果没有图片想设置圆角,可以直接设置</code>
button.layer.cornerRadius = radius
<code>//但不要设置</code>
button.layer.masksToBounds = true
或 button.clipsToBounds = true
<code>//不然也会有有离屏渲染</code>
效果图
UILabel 设置圆角
label.text = @"1";
label.textColor = [UIColor whiteColor];
label.font = [UIFont systemFontOfSize:12];
label.layer.backgroundColor = [UIColor greenColor].CGColor;
label.layer.cornerRadius = 2;