如果我使用圆形图像,图像不会显示在imageView中 [英] Image not showing in imageView if I used circular image
问题描述
我有一个表视图,我需要在节头中显示author_img。在ViewForSectionHeader方法中,我想使图像为圆形。但是,如果我这样做,那么无论是在模拟器还是在真实设备中,图像都不会显示出来。如果我删除代码,uiimageview将正常显示图像。我为uiimageview设置了宽度和高度约束,因为我想获得显示图像的固定大小。那么有什么想法吗?
I have a table view and I need to show author_img in section header. In ViewForSectionHeader method, I want to make the image to be circular. But If I did that, the images are not showing at all, no matter in simulator or in real device. If I remove the code, uiimageview will show the images normally. I set up the width and height constraint for uiimageview because I want to get fixed size of showing images. So Any ideas, please?
cell.author_img.layer.cornerRadius = cell.author_img.frame.size.width/2
cell.author_img.layer.masksToBounds = true
// add a boundary for thumb
cell.author_img.layer.borderWidth = 1.5
cell.author_img.layer.borderColor = UIColor.whiteColor().CGColor
推荐答案
这可能来自事实如果您过早地设置了cornerRadius,则 author_img
的最终大小尚未修复。
当您确定完全计算了单元格的布局时,尝试设置cornerRadius。
It may come from the fact that you are setting the cornerRadius too early, the final size of your author_img
is not fixed yet.
Try to set that cornerRadius when you are sure that the layout of your cell has been entirely calculated.
出于测试目的,只是为了确保它即将到来从这种行为,尝试硬编码cornerRadius。
For test purpose, just to make sure it is coming from this behaviour, try to hardcode the cornerRadius.
cell.author_img.layer.cornerRadius = 10
如果你的图像有一个轻微的cornerRadius,这意味着问题来自我之前解释过的,如果它还没有显示,它来自其他东西。
If your image has a slight cornerRadius, it means that the issue is coming from what I explained earlier, if it is still not showing, it is coming from something else.
如果它确实来自图像大小不固定的事实,请尝试将您的cornerRadius设置为 viewDidAppear
,我的意思是你能做的最新事情。
If it does come from the fact the size of your image is not fixed, try to set your cornerRadius in something like viewDidAppear
, I mean the latest you can do.
这篇关于如果我使用圆形图像,图像不会显示在imageView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!