UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(100, 100, 100, 100);
[self.view addSubview:btn];
// 设置曲线
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:btn.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(50, 50)];
// 设置蒙层
CAShapeLayer *layer = [CAShapeLayer layer];
layer.frame = btn.bounds;
layer.path = path.CGPath;
btn.layer.mask = layer;
// 设置一个和蒙层大小相同的layer,设置颜色和宽度,添加到button上
CAShapeLayer *boderLayer = [CAShapeLayer layer];
boderLayer.frame = btn.bounds;
boderLayer.path = path.CGPath;
boderLayer.strokeColor = [UIColor greenColor].CGColor;
boderLayer.fillColor = [UIColor clearColor].CGColor;
boderLayer.lineWidth = 1.f;
[btn.layer addSublayer:boderLayer];
标签:圆角,boderLayer,CAShapeLayer,layer,边框,UIButton,path,btn
From: https://www.cnblogs.com/hwfengZxk/p/18394718