UIImageView四个角加不同的圆角的方法

- (void)setCornerRadiusWithTopLeft:(CGFloat)topLefttopRight:(CGFloat)topRightbottomLeft:(CGFloat)bottomLeftbottomRight:(CGFloat)bottomRightimageView:(UIImageView*)imageView{

    CGFloatminX =CGRectGetMinX(imageView.bounds);

    CGFloatminY =CGRectGetMinY(imageView.bounds);

    CGFloatmaxX =CGRectGetMaxX(imageView.bounds);

    CGFloatmaxY =CGRectGetMaxY(imageView.bounds);

    CGFloattopLeftCenterX = minX + topLeft;

    CGFloattopLeftCenterY = minY + topLeft;

    CGFloattopRightCenterX = maxX - topRight;

    CGFloattopRightCenterY = minY + topRight;

    CGFloatbottomLeftCenterX = minX + bottomLeft;

    CGFloatbottomLeftCenterY = maxY - bottomLeft;

    CGFloatbottomRightCenterX = maxX - bottomRight;

    CGFloatbottomRightCenterY = maxY - bottomRight;

    UIBezierPath *path = [UIBezierPath bezierPath];

    [pathaddArcWithCenter:CGPointMake(topLeftCenterX, topLeftCenterY)radius:topLeftstartAngle:M_PIendAngle:3*M_PI/2.0clockwise:YES];

    [pathaddArcWithCenter:CGPointMake(topRightCenterX, topRightCenterY)radius:topRightstartAngle:3*M_PI/2.0endAngle:0clockwise:YES];

    [pathaddArcWithCenter:CGPointMake(bottomRightCenterX, bottomRightCenterY)radius:bottomRightstartAngle:0endAngle:M_PI_2clockwise:YES];

    [pathaddArcWithCenter:CGPointMake(bottomLeftCenterX, bottomLeftCenterY)radius:bottomLeftstartAngle:M_PI_2endAngle:M_PIclockwise:YES];

    CAShapeLayer*masklayer = [[CAShapeLayeralloc]init];

    masklayer.frame= imageView.bounds;

    masklayer.path= path.CGPath;

    imageView.layer.mask= masklayer;

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容