ios中的圆角图片做法

ios中很多头像图标都要圆角的,好看用户体验好。入下图:

ios中的圆角图片做法_第1张图片
image.png

具体怎么做的呢?

  • 方式一:
    objc
    // 设置头像圆角,iOS9苹果修复,支持
    // _iconView.layer.cornerRadius = 30;
    // _iconView.layer.masksToBounds = YES;
注意:30为图片宽高的一半,这种做法多图片的时候会卡,不建议使用。
- 方式二:

```objc```
 [_iconView sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        // 1.开启图形上下文
        // 比例因素:当前点与像素比例
        UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
        // 2.描述裁剪区域
        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
        // 3.设置裁剪区域;
        [path addClip];
        // 4.画图片
        [image drawAtPoint:CGPointZero];
        // 5.取出图片
        image = UIGraphicsGetImageFromCurrentImageContext();
        // 6.关闭上下文
        UIGraphicsEndImageContext();
        
        _iconView.image = image;

    }];

你可能感兴趣的:(ios中的圆角图片做法)