31.UIImageView

UIImageView等比例加载图片

self.imageView.contentMode  = UIViewContentModeScaleAspectFit;
self.imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

为UIImageView添加圆角

第一种方法:
UIGraphicsBeginImageContextWithOptions(self.imageView.frame.size, NO, 1.0);
[[UIBezierPath bezierPathWithRoundedRect:self.imageView.bounds cornerRadius:10]addClip];
[image drawInRect:self.imageView.bounds];
self.imageView.image    = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
第二种方法:

添加image的分类

- (UIImage *)circleImage
{
    UIGraphicsBeginImageContext(self.size);
    CGContextRef context    = UIGraphicsGetCurrentContext();
    CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
    CGContextAddEllipseInRect(context, rect);
    CGContextClip(context);

    [self drawInRect:rect];
    
    UIImage *image  = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

+ (UIImage *)getCircleImage:(NSString *)image
{
    return [[self imageNamed:image] circleImage];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,262评论 4 61
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,152评论 5 13
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,586评论 6 30
  • 这次的主题,拍的最好的一次拍照。我的结论是,笑起来,拍出的效果都不错!有图为证! 发自内心的笑,应该是最美的了吧!...
    孙晓丽阅读 330评论 2 2
  • 清晨,大约是我在这个城市最心静的时候。 天空,灰蒙蒙。 配合着灰色的高楼,尤其显出这个城市的冷静。 卧在飘窗,可以...
    秦子木222阅读 288评论 0 0