在繁杂的需求过程中,会遇到各种各样的圆角或者边框的需求,如何高效的设置圆角边框等呢?避免离屏渲染,等高效的渲染,我们选择的贝塞尔曲线去画圆角。
一、四周圆角,指定角度大小,方向也可自定义
- (void)bezierRoundCornersWithCornerRadius:(CGFloat)cornerRadius{
[self bezierCornerWithApplyRoundCorners:UIRectCornerAllCorners radius:cornerRadius];
}
- (void)bezierCornerWithApplyRoundCorners:(UIRectCorner)corners
radius:(CGFloat)radius{
UIBezierPath *path;
path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.bounds;
maskLayer.path = path.CGPath;
self.layer.mask = maskLayer;
}
二、设置边框
- (void)bezierBorderWithStrokeColor:(UIColor *)strokeColor
lineWidth:(CGFloat)lineWidt