- @interface UIView (RectCorner)
- @end
- @implementation UIView (RectCorner)
- - (void)setCornerOnTop {
- UIBezierPath *maskPath;
- maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
- byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
- cornerRadii:CGSizeMake(10.0f, 10.0f)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = self.bounds;
- maskLayer.path = maskPath.CGPath;
- self.layer.mask = maskLayer;
- [maskLayer release];
- }
- - (void)setCornerOnBottom {
- UIBezierPath *maskPath;
- maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
- byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)
- cornerRadii:CGSizeMake(10.0f, 10.0f)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = self.bounds;
- maskLayer.path = maskPath.CGPath;
- self.layer.mask = maskLayer;
- [maskLayer release];
- }
- - (void)setAllCorner {
- UIBezierPath *maskPath;
- maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
- cornerRadius:10.0];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = self.bounds;
- maskLayer.path = maskPath.CGPath;
- self.layer.mask = maskLayer;
- [maskLayer release];
- }
- - (void)setNoneCorner{
- self.layer.mask = nil;
- }
- @end
设置UIView圆角的拓展
最新推荐文章于 2025-08-24 09:56:29 发布
本文介绍了一种在iOS开发中为UIView设置不同位置圆角的方法。通过使用UIBezierPath和CAShapeLayer,可以轻松实现顶部、底部或所有角落的圆角效果。
7774

被折叠的 条评论
为什么被折叠?



