圆形图像变成钻石而不是圆形 - Swift 3 [英] Circular Image Becoming a Diamond Not Circle - Swift 3

查看:30
本文介绍了圆形图像变成钻石而不是圆形 - Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试创建一个圆形图像,但由于某种原因它一直输出为钻石.这是我的代码:

I have been trying to create a circular image but for some reason it has been outputting as a diamond. This is my code:

override func viewDidLoad() {
    displayEmailFullNameImage()

    self.editProfilePictureImage.layer.cornerRadius = editProfilePictureImage.frame.size.width / 2
    self.editProfilePictureImage.clipsToBounds = true
    self.editProfilePictureImage.contentMode = .scaleAspectFill

}

我对照片的限制:

我尝试了以下解决方案:

I have tried the following solution:

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    profilePic.layer.cornerRadius = profilePic.frame.width / 2
    profilePic.clipsToBounds = true
}

但这也不起作用.

这就是图像的外观:

任何帮助将不胜感激.

推荐答案

您的问题可能是由于您在 imageView 中添加了一些约束.尝试只添加 4 个约束,1 个用于固定宽度,1 个用于固定高度,1 个用于前导空间,1 个用于顶部空间,如下面的屏幕截图所示:

Your problem it is probably caused by some constraints you have added to your imageView. Try adding only 4 constraints, 1 for fixed width, 1 for fixed height, 1 for leading space and 1 for top space as you can see at the screenshot below:

这篇关于圆形图像变成钻石而不是圆形 - Swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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