首页 > iOS UIScrollView 设置圆角的问题

iOS UIScrollView 设置圆角的问题

怎样给UIScrollView设置圆角 而且设置上边两个角是圆角


不仅仅适用于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?

【热门文章】
【热门文章】