ios - UITableView 中的圆形 UIImageView 没有性能影响?

我的每个 UITableView 单元格上都有一个 UIImageView,用于显示远程图像(使用 SDWebImage)。我对 ImageView 做了一些 QuartzCore 图层样式,例如:

UIImageView *itemImageView = (UIImageView *)[cell viewWithTag:100];
    itemImageView.layer.borderWidth = 1.0f;
    itemImageView.layer.borderColor = [UIColor concreteColor].CGColor;
    itemImageView.layer.masksToBounds = NO;
    itemImageView.clipsToBounds = YES;

所以现在我有一个带有浅灰色边框的 50x50 正方形,但我想让它变成圆形而不是正方形。 Hemoglobe 应用程序在表格 View 中使用圆形图像,这就是我想要实现的效果。但是,我不想使用 cornerRadius,因为这会降低我的滚动 FPS。

这是显示圆形 UIImageViewsHemoglobe:

有什么办法可以达到这个效果吗?谢谢。

最佳答案

只需将 cornerRadius 设置为宽度或高度的一半(假设您的对象的 View 是方形的)。

例如,如果您的对象的 View 的宽度和高度都是 50:

itemImageView.layer.cornerRadius = 25;

更新 - 正如用户 atulkhatri 指出的那样,如果您不添加,它将无法工作:

itemImageView.layer.masksToBounds = YES;

https://stackoverflow.com/questions/17721934/

相关文章:

objective-c - 在 Objective-C 中将所有文本转换为小写

objective-c - 值/对象的 NSDictionary 键?

objective-c - NSString 到 CFStringRef 和 CFStringRef

ios - 在 SKScene 中设置按钮

iphone - Objective-C 将 NSDate 设置为当前 UTC

objective-c - 如何在 Swift 项目中使用 Objective-C CocoaPod

objective-c - 如何使用 AFNetworking 设置超时

objective-c - 如何为单个文件启用 ARC

objective-c - 基于 View 的 NSTableView 具有动态高度的行

objective-c - sizeWithFont 方法已弃用。 boundingRectWith