ios swift 3 xcode8 beta 圆角 imageView [英] ios swift 3 xcode8 beta rounded imageView

查看:20
本文介绍了ios swift 3 xcode8 beta 圆角 imageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我使用以下代码使我的图像呈圆形:

With my project I use the following code in order to make my images in rounded shape:

profileImage.layer.cornerRadius = profileImage.frame.size.width / 2
profileImage.clipsToBounds = true

我还对我的图像使用了约束以使其width = hight,以及其他约束.

I also use contrains for my image to make it width = hight, and other constrains.

将我的项目升级到 xcode 8 beta 和 swift 3 之后,我设置为四舍五入的所有图像视图都消失了,当我删除使其四舍五入的代码或删除所有限制它们再次出现.
但我仍然需要将它们四舍五入.任何人都可以帮助我解决问题.谢谢

After ugrading my project to xcode 8 beta, and swift 3. All the images views that I set to rounded were disappeared, and when I remove the code for making it rounded or I remove all the constrains they appear again.
But I still need them to be rounded. Anyone can help me to fix the issue. Thanks

推荐答案

我也遇到了同样的问题,解决方法就是在修改图层之前移动一行代码.尝试应用布局更改:

I had the same problem, the solution was just to move a line of code before your layer modifications. Try to apply layout changes:

self.view.layoutIfNeeded()

在您的代码之前:

profileImage.layer.cornerRadius = profileImage.frame.size.width/2
profileImage.clipsToBounds = true

将与框架/层相关的代码放入viewDidLayoutSubviews()方法中:

place your code related to frames / layers into viewDidLayoutSubviews() method:

override func viewDidLayoutSubviews() {

    profileImage.layer.cornerRadius = profileImage.frame.size.width/2
    profileImage.clipsToBounds = true

}

这篇关于ios swift 3 xcode8 beta 圆角 imageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆