iOS 视图切部分圆角

日常开发中,可能某些需求需要我们对当前视图进行部分圆角切割,那,我们怎么去处理呢?

显然

view.layer.cornerRadius = cornerRadius;
view.layer.masksToBounds = YES;

已满足不了需求!

那下面,给大家提供了一个方法,希望对大家日常开发有帮助,具体如下:

/**
 切部分圆角
 
 UIRectCorner有五种
 UIRectCornerTopLeft //上左
 UIRectCornerTopRight //上右
 UIRectCornerBottomLeft // 下左
 UIRectCornerBottomRight // 下右
 UIRectCornerAllCorners // 全部
 
 @param cornerRadius 圆角半径
 */
- (void)setPartRoundWithView:(UIView *)view corners:(UIRectCorner)corners cornerRadius:(float)cornerRadius {
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(cornerRadius, cornerRadius)].CGPath;
    view.layer.mask = shapeLayer;
}

欢迎大家访问我的GitHub

GitTub:https://github.com/JnKindle

猜你喜欢

转载自blog.csdn.net/RangingWon/article/details/81565687
今日推荐