美文网首页
iOS 图片圆角(CoreGraphics 绘制)

iOS 图片圆角(CoreGraphics 绘制)

作者: 是夏目啊 | 来源:发表于2017-07-06 16:40 被阅读0次
    - (UIImage *)imageAddCornerWithRadius:(CGFloat)radius andSize:(CGSize)size{
        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);
        [self drawInRect:rect];
        CGContextDrawPath(ctx, kCGPathFillStroke);
        UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return newImage;
    }
    
    

    相关文章

      网友评论

          本文标题:iOS 图片圆角(CoreGraphics 绘制)

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