一句代码,圆角风雨无阻。A Category to make cornerRadius for UIImageView have no Offscreen-Rendered, be more efficiency.
##CocoaPods:
pod 'ZYCornerRadius', '~> 1.0.2'
##性能对比: 测试设备6P,屏幕中有40张尺寸为20*20的小图片,使用masksToBounds切角处理时帧率大大下降至20+,使用ZYCornerRadius时帧率保持在57+,性能接近0损耗。
内存使用对比:
导入头文件
#import "UIImageView+CornerRadius.h"
创建圆角半径为6的UIImageView(两种种方式):
//1
UIImageView *imageView = [[UIImageView alloc] initWithCornerRadiusAdvance:6.0f rectCornerType:UIRectCornerAllCorners];
//2
UIImageView *imageView = [[UIImageView alloc] init];
[imageView zy_cornerRadiusAdvance:6.0f rectCornerType:UIRectCornerAllCorners];
创建圆形的UIImageView(两种方式):
//1
UIImageView *imageView = [[UIImageView alloc] initWithRoundingRectImageView];
//2
UIImageView *imageView = [[UIImageView alloc] init];
[imageView zy_cornerRadiusRoundingRect];
可为UIImageView的图片附加边框:
[imageView zy_attachBorderWidth:1.f color:[UIColor redColor]];
按你的需要完成配置后,任何时候对UIImageView setImage,效果都会生效
//anytime
imageView.image = [UIImage imageNamed:@"mac_dog"];