美文网首页
ios 绘制圆角图片的另一种方式

ios 绘制圆角图片的另一种方式

作者: lizhi_boy | 来源:发表于2016-12-16 13:52 被阅读160次
    #pragma mark - 绘制圆角图片
    
    - (UIImage*)imageAddCornerWithRadius:(CGFloat)radius andSize:(CGSize)size andImage:(UIImage *)image{
        
        CGRect rect = CGRectMake(0, 0, size.width, size.height); UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(radius, radius)];
        CGContextAddPath(ctx,path.CGPath);
        CGContextClip(ctx);
        [image drawInRect:rect];
        CGContextDrawPath(ctx, kCGPathFillStroke);
        UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return newImage;
        
    }
    

    相关文章

      网友评论

          本文标题:ios 绘制圆角图片的另一种方式

          本文链接:https://www.haomeiwen.com/subject/raunmttx.html