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,257評論 4 61
  • 在iOS中隨處都可以看到絢麗的動畫效果,實現這些動畫的過程并不復雜,今天將帶大家一窺iOS動畫全貌。在這里你可以看...
    F麥子閱讀 5,147評論 5 13
  • 在iOS中隨處都可以看到絢麗的動畫效果,實現這些動畫的過程并不復雜,今天將帶大家一窺ios動畫全貌。在這里你可以看...
    每天刷兩次牙閱讀 8,573評論 6 30
  • 這次的主題,拍的最好的一次拍照。我的結論是,笑起來,拍出的效果都不錯!有圖為證! 發自內心的笑,應該是最美的了吧!...
    孫曉麗閱讀 325評論 2 2
  • 清晨,大約是我在這個城市最心靜的時候。 天空,灰蒙蒙。 配合著灰色的高樓,尤其顯出這個城市的冷靜。 臥在飄窗,可以...
    秦子木222閱讀 278評論 0 0