在 UIImageView 中裁剪的圆角 [英] Rounded corners clipped in UIImageView

查看:41
本文介绍了在 UIImageView 中裁剪的圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 tableViewCells 中的 UIImageView 上圆角,但是,由于某种原因,它们被剪掉了.我试过这个:

I am trying to round the corners on my UIImageView in tableViewCells, however, for some reason, they are clipped. I have tried this:

cell.characterThumbnail.layer.masksToBounds = true
cell.characterThumbnail.layer.cornerRadius = 15

这是我得到的结果:

如果我使用调试 3D 查看器,我得到的帧比我设置的要大(我想要 84 * 84,但它显示 84 * 110).此处显示:

If I use the debug 3D viewer I get the frame is larger than I've set (I want 84 * 84 but it shows 84 * 110). Shown here:

为什么会有不同的尺寸?为什么圆角被剪掉了?我必须指出 UIImageView 中的图像是从每个缩略图的 URL 下载的.

Why are there different sizes? And why are the rounded corners clipped? I have to point out that the image in the UIImageView is downloaded from an URL for each thumbnail.

非常感谢您对此事的任何帮助.它困扰了我一个星期,哈哈.

Any help on this matter is much appreciated. It has bugged me for a week lol.

附言我忘了提到我在 SO 和互联网上的其他地方阅读了几乎所有圆角"问题,但没有提到剪角.另外,在 UIImageView 中显示它之前,我曾考虑过将实际图像四舍五入,但这会使 tableView 滚动抖动.

P.S. I forgot to mention that I've read almost every single "rounded corner" question here on SO and elsewhere on the internet, but no mention of clipped corners. Also, I have thought about rounding the actual image before displaying it in the UIImageView, but that makes the tableView scrolling jerky.

整个项目位于 https://github.com/Aecasorg/WoWilvlChecker

推荐答案

都是因为约束.我所需要的只是摆脱我设置的前导空间:超级视图"和底部视图:超级视图"约束,并添加一个将 Y 中心对齐:超级视图"并对其进行排序.感谢大家的回复和建议!

It is all due to constraints. All I needed was to get rid of the "Leading Space to: Superview" and "Bottom View to: Superview" constraints I had set up and add an "Align Center Y to: Superview" and that sorted it. Thanks to everyone for responses and suggestions!

这篇关于在 UIImageView 中裁剪的圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆