MXCornerRadius 只需1行代码让你的UIImageView 有任意的cornerRadius圆角!

代码demo已在Github开源, MXCornerRadius 若是帮助到您,点个星star哈!git

MXCornerRadius 只需1行代码让你的imageView 有任意的cornerRadius圆角!github

对象结构

Structure.png

屏幕截图

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;`
复制代码

mxDisableRoundImageCache

默认是 NO,启用缓存,MXImageObserver缓存圆角图片是为了提升FPS帧率;当设置为YES, 禁用缓存,当imageView有新的图片或者mxCornerRadius改变或者contentMode 改变,CPU每一次都会从新生成圆角图片,老iPhone估计会影响性能,因此建议用默认设置(启用缓存),可是要注意当- [imageView dealloc] 调用后,与imageView绑定的MXObserver对象也会被销毁,那么它缓存的全部圆角图片也会随之销毁,所以不可能有内存泄漏!具体看demo.性能

avatarImageView.mxDisableRoundImageCache = YES;
复制代码

printDebugLogForRoundImageCache

默认是 NO,不打印信息,避免影响生产环境的性能,但在demo中已手动设置为YES;当设置为YES时,控制台会实时监听缓存图片的变化,如增长缓存,以及当- [imageView dealloc]调用后,缓存会被删除,打印出当前imageView.MXImageObserver对象已经缓存的圆角图片以及其余imageView.MXImageObserver对象已经缓存的圆角图片,它们是一个集合类型。spa

[MXRoundImageCacheManager sharedManager].shouldPrintDebugLogForRoundImageCache = YES;
复制代码
相关文章
相关标签/搜索