美文网首页
iOS UIImageView 圆角

iOS UIImageView 圆角

作者: Justin_W | 来源:发表于2018-03-13 16:28 被阅读0次

view.layer.cornerRadius = 3.f;

// 不用写
view.layer.masksToBounds = YES;
view.clipToBounds = YES;


@implementation UIImage (extend)

- (UIImage *)drawRectWithRoundedCorner
{
    CGRect rect = CGRectMake(0.f, 0.f, 150.f, 150.f);
    
    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:rect.size.width * 0.5];
    UIGraphicsBeginImageContextWithOptions(rect.size, false, [UIScreen mainScreen].scale);
    CGContextAddPath(UIGraphicsGetCurrentContext(), bezierPath.CGPath);
    CGContextClip(UIGraphicsGetCurrentContext());
    [self drawInRect:rect];
 
    CGContextDrawPath(UIGraphicsGetCurrentContext(), kCGPathFillStroke);
    UIImage *output = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return output;
}
@end

相关文章

网友评论

      本文标题:iOS UIImageView 圆角

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