[英]ios swift 3 xcode8 beta rounded imageView
在我的项目中,我使用以下代码使我的图像呈圆形:
profileImage.layer.cornerRadius = profileImage.frame.size.width / 2
profileImage.clipsToBounds = true
我还对我的图像使用了限制,使其width = hight
和其他限制。
在将我的项目升级到xcode 8 beta和 swift 3 之后,我设置为四舍五入的所有图像视图都消失了,当我删除使其四舍五入的代码或删除所有约束时,它们再次出现。
但我仍然需要将它们四舍五入。 任何人都可以帮助我解决问题。 谢谢
我遇到了同样的问题,解决方案只是在修改图层之前移动一行代码。 尝试应用布局更改:
self.view.layoutIfNeeded()
在您的代码之前:
profileImage.layer.cornerRadius = profileImage.frame.size.width/2
profileImage.clipsToBounds = true
或者
将与框架/层相关的代码放入viewDidLayoutSubviews()
方法中:
override func viewDidLayoutSubviews() {
profileImage.layer.cornerRadius = profileImage.frame.size.width/2
profileImage.clipsToBounds = true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.