不仅仅适用于UIScrollView,可以使用在任何UIView上。 1. 给UIView添加一个Category @implementation UIView (UIViewRoundCorners) - (void)applyRoundCorners:(UIRectCorner)corners radius:(CGFloat)radius { UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = self.bounds; maskLayer.path = maskPath.CGPath; self.layer.mask = maskLayer; } @end 2. 设置上面左右两个角变圆 [view applyRoundCorners:UIRectCornerTopRight|UIRectCornerTopLeft radius:10]; 参考 Rounded UIView using CALayers - only some corners - How?
不仅仅适用于
UIScrollView
,可以使用在任何UIView
上。1. 给
UIView
添加一个Category
2. 设置上面左右两个角变圆
参考
Rounded UIView using CALayers - only some corners - How?