?平時(shí)開發(fā)中給圖片設(shè)置圓角都是
self.iconImage.layer.cornerRadius = 20;
self.iconImage.layer.masksToBounds = YES;
或者只在xib&storyboard中點(diǎn)擊要設(shè)置圓角的圖片
之后建議大家不要這樣設(shè)置了,因?yàn)槭褂脠D層過量會(huì)有卡頓現(xiàn)象,特別是弄圓角或者陰影會(huì)很卡,如果要設(shè)置一個(gè)圓角的效果,我們一般用繪圖來做:
/** 設(shè)置圓形圖片(放到分類中使用) */
- (UIImage *)cutCircleImage {
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
// 獲取上下文
CGContextRef ctr = UIGraphicsGetCurrentContext();
// 設(shè)置圓形
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextAddEllipseInRect(ctr, rect);
// 裁剪
CGContextClip(ctr);
// 將圖片畫上去
[self drawInRect:rect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
這個(gè)方法就是設(shè)置圖片圓角,效率很高,不會(huì)出現(xiàn)卡頓的現(xiàn)象.