问题描述
我的每个 UITableView
单元格上都有一个 UIImageView
,它显示一个远程图像(使用 SDWebImage
)。我已经为图像视图做了一些 QuartzCore
图层样式,如下所示:
I have a UIImageView
on each of my UITableView
cells, that display a remote image (using SDWebImage
). I've done some QuartzCore
layer styling to the image view, as such:
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的正方形,带有微弱的灰色边框,但是我想要它圆形而不是平方。应用血红蛋白
在表格视图中使用圆形图像,这就是我想要实现的效果。但是,我不想使用 cornerRadius
,因为这会降低我的滚动FPS。
So now I have a 50x50 square with a faint grey border, but I'd like to make it circular instead of squared. The app Hemoglobe
uses circular images in table views, and that's the effect I'd like to achieve. However, I don't want to use cornerRadius
, as that degrades my scrolling FPS.
这是血红蛋白
显示圆形 UIImageViews
:
有没有办法达到这个效果?谢谢。
Is there any way to get this effect? Thanks.
推荐答案
只需将 cornerRadius
设置为宽度的一半或高度(假设你的对象的视图是方形的)。
Simply set the cornerRadius
to half of the width or height (assuming your object's view is square).
例如,如果你的对象的视图的宽度和高度都是50:
For example, if your object's view's width and height are both 50:
itemImageView.layer.cornerRadius = 25;
更新 - 正如用户atulkhatri指出的那样,如果你不添加它将无法工作:
Update - As user atulkhatri points out, it won't work if you don't add:
itemImageView.layer.masksToBounds = YES;
这篇关于UITableView中的圆形UIImageView没有性能损失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!