我有一个 UIView
,其中有一个 UIImageView
。
我将 UIImageView
设置为圆形,并为其添加边框,如下所示:
self.profilePicImageView.layer.cornerRadius = self.profilePicImageView.frame.size.height / 2
self.profilePicImageView.layer.masksToBounds = true
self.profilePicImageView.layer.borderColor = UIColor.white.cgColor
self.profilePicImageView.layer.borderWidth = 3
在我初始化 viewController
中的 View 之后以及将其添加为 subview (名为 setupUI()
的函数)之前,它会被调用。
它在大多数设备上工作得很好,但在大屏幕设备(iPhone 6/6s/7 Plus 和 iPhone X)上我得到了正确的边框,但图像本身不是圆形的。
请参阅示例:
普通 iPhone:
大型 iPhone(iPhone 6/6s/7 Plus 和 iPhone X):
知道问题是什么以及如何解决它吗?
谢谢!!
最佳答案
只需尝试此代码,它会对您有所帮助。
imageView.layer.cornerRadius = imageHeight/2
imageView.layer.masksToBounds = true
imageView.contentMode = .scaleAspectFill
关于ios - 圆形 UIImageView 在某些设备上是方形的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46988121/