设置一边圆角
缺点:不能设置颜色,正在研究。
typedef NS_ENUM(NSInteger, CNButtonSide) {
CNButtonSideLeft,
CNButtonSideRight,
CNButtonSideUp,
CNButtonSideDown
};
- (void)roundSide:(CNButtonSide)side
{
UIBezierPath *maskPath;
if (side == CNButtonSideLeft)
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerBottomLeft)
cornerRadii:CGSizeMake(8.f, 8.f)];
else if (side == CNButtonSideRight)
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopRight|UIRectCornerBottomRight)
cornerRadii:CGSizeMake(8.f, 8.f)];
else if (side == CNButtonSideUp)
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
cornerRadii:CGSizeMake(8.f, 8.f)];
else
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight)
cornerRadii:CGSizeMake(8.f, 8.f)];
// Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
// Set the newly created shape layer as the mask for the image view's layer
self.layer.mask = maskLayer;
[self.layer setMasksToBounds:YES];
}
网友评论