代码demo已在Github开源, MXCornerRadius 若是帮助到您,点个星star哈!git
MXCornerRadius
只需1行代码让你的imageView
有任意的cornerRadius圆角!github
当avatarImgView.mxCornerRadius=xxXX 改变时,单个imgView 实时显示圆角image |
imgView.mxDisableRoundImageCache = NO, 默认是NO,缓存图片,高 FPS | imgView.mxDisableRoundImageCache = YES, 不缓存图片 |
---|---|---|
![]() |
![]() |
![]() |
当mxCornerRadius
改变时,单个avatarImageView
实时显示圆角image缓存
UIImageView *avatarImageView = [[UIImageView alloc] initWithFrame:CGRectMake(...)];
avatarImageView.image = [UIImage imageNamed:@"foo.png"];
`avatarImageView.mxCornerRadius = 10.0f;`
复制代码
默认是 NO
,启用缓存,MXImageObserver
缓存圆角图片是为了提升FPS帧率;当设置为YES
, 禁用缓存,当imageView
有新的图片或者mxCornerRadius
改变或者contentMode
改变,CPU每一次都会从新生成圆角图片,老iPhone估计会影响性能,因此建议用默认设置(启用缓存),可是要注意当- [imageView dealloc] 调用后
,与imageView
绑定的MXObserver
对象也会被销毁,那么它缓存的全部圆角图片也会随之销毁,所以不可能有内存泄漏!具体看demo
.性能
avatarImageView.mxDisableRoundImageCache = YES;
复制代码
默认是 NO
,不打印信息,避免影响生产环境的性能,但在demo中已手动设置为YES
;当设置为YES
时,控制台会实时监听缓存图片的变化,如增长缓存,以及当- [imageView dealloc]
调用后,缓存会被删除,打印出当前imageView.MXImageObserver
对象已经缓存的圆角图片以及其余imageView.MXImageObserver
对象已经缓存的圆角图片,它们是一个集合类型。spa
[MXRoundImageCacheManager sharedManager].shouldPrintDebugLogForRoundImageCache = YES;
复制代码