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

标签 ios objective-c 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:

enter image description here

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

最佳答案

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

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

itemImageView.layer.cornerRadius = 25;

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

itemImageView.layer.masksToBounds = YES;

关于ios - UITableView 中的圆形 UIImageView 没有性能影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17721934/

相关文章:

ios - prepareForSegue 从未调用过

iOS 9 - App Transport Security 不会加载 XML 文件

objective-c - 我如何制作一个简单的基于 View 的 NSOutlineView?

iphone - 如何处理 MKMapView 上数百个 map 注释导致的延迟?

ios - 奇怪的 Xcode 自动完成

ios - 如何删除单元格内容的左填充?

swift - 如何访问数据模型 [字符串 : [String]] in UITableView with sections?

iphone - 访问存储在应用程序中的文件的最快方法

ios - 保存高分并在 Game Center 排行榜中显示不同的排行榜

iOS - Unity 应用程序上的 Swift SDK 集成