About UIImageView with round corners

不羁的心 提交于 2019-12-04 06:17:47

问题


I'm trying to make a UIImageView with round corners, so I used [imageView.layer setCornerRadius:5.0f]; it works but not perfectly.

If you look closely, you can see the corners of the image(I uploaded a photo, I don't know if you can see it clearly, there are blue parts in the corners). How should I remove these? thank you.

(P.S.: I also set the border of the view, is that the reason why?)


回答1:


UIImageView doesn't clip to bounds by default. So while the corner radius is applied its still drawing outside of its designated area.

objc:

[imageView setClipsToBounds:YES];

swift:

imageView.clipsToBounds = true


来源:https://stackoverflow.com/questions/27803041/about-uiimageview-with-round-corners

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!