我们都知道iOS视图圆角
[view.layer setCornerRadius:5];
但是某些需求上可能我们只需要指定View的某几个角为圆角
例如:
素材001.png
图中框出的橘色部分我们只需要左半块圆角,这种要怎么实现呢
UIRectCorner rectCorner = UIRectCornerBottomLeft | UIRectCornerTopLeft;
//任意视图
UIView *testView = [[UIView alloc] init];
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:testView.bounds byRoundingCorners:rectCorner cornerRadii:CGSizeMake(5, 5)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = testView.bounds;
maskLayer.path = bezierPath.CGPath;
testView.layer.mask = maskLayer;
//UIRectCorner所有的值
typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
UIRectCornerTopLeft = 1 << 0,
UIRectCornerTopRight = 1 << 1,
UIRectCornerBottomLeft = 1 << 2,
UIRectCornerBottomRight = 1 << 3,
UIRectCornerAllCorners = ~0UL
};
网友评论