【发布时间】:2018-04-09 19:57:05
【问题描述】:
我有一个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 中的视图之后以及在我将其添加为子视图之前调用它(函数名为 setupUI())。
它在大多数设备上都能正常工作,但在大屏幕设备(iPhone 6/6s/7 Plus 和 iPhone X)上,我的边框是正确的,但图像本身不是圆形的。
请查看示例:
普通 iPhone:
大型 iPhone(iPhone 6/6s/7 Plus 和 iPhone X):
知道问题可能是什么,我该如何解决?
谢谢!!
【问题讨论】:
-
@FS.06 我也面临这个问题,所以添加以下代码 self.profilePicImageView.contentMode = .scaleAspectFill self.profilePicImageView.clipsToBounds = true
-
@FS.O6 请尝试我编辑的答案,它对我有用
标签: ios iphone swift cocoa-touch uiview