關于UIBezierPath
網(wǎng)上有很多相關的內容,在此不再累述,自行百度或谷歌
給UIButton 畫圓角
1、創(chuàng)建 UIBezierPath
// byRoundingCorners 設置需要切圓角的屬性
UIBezierPath *roundPath = [UIBezierPath bezierPathWithRoundedRect:self.drawRec.frame byRoundingCorners:UIRectCornerTopRight |UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
2、創(chuàng)建 CAShapeLayer
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = self.yourButton.frame;
shapeLayer.path = roundPath.CGPath;
shapeLayer.lineWidth = 2.f;
shapeLayer.strokeColor = [UIColor redColor].CGColor;
shapeLayer.fillColor = [UIColor clearColor].CGColor;
3洞辣、使用
// 使用二者的差異
/**
邊線顏色使用的是yourButton.BackgroundColor
設置 strokeColor 無用,
*/
self.yourButton.layer.mask = shapeLayer;
/**
邊線顏色是 strokeColor 的顏色
*/
[self.yourButton.layer addSublayer:shapeLayer];