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

查看:136
本文介绍了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

OR

将与帧/图层相关的代码放入 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天全站免登陆