在我的项目中,我使用以下代码使图像呈圆形:
profileImage.layer.cornerRadius = profileImage.frame.size.width / 2
profileImage.clipsToBounds = true我还使用对比作为我的图像,使其width = hight,和其他约束。
在将我的项目升级为xcode 8 beta和swift 3之后,我设置为四舍五入的所有图像视图都消失了,当我删除使其四舍五入的代码或删除所有约束时,它们再次出现。
但我还是需要他们的圆润。任何人都可以帮我解决这个问题。谢谢
发布于 2016-08-18 13:34:26
我也有同样的问题,解决方案就是在您的层修改之前移动一行代码。尝试应用布局更改:
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
}https://stackoverflow.com/questions/38954368
复制相似问题