2016-11-15 99 views
2

我一直在试图创建一个圆形图像,但出于某种原因它已经输出为钻石。这是我的代码:圆形图像成为钻石不圆圈 - 斯威夫特3

override func viewDidLoad() { 
    displayEmailFullNameImage() 

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

} 

我的照片约束:

enter image description here

我曾尝试以下解决方案:

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

但这也不管用。

这是图像的外观:

enter image description here

任何帮助,将不胜感激。

+0

你的问题很可能是由于您添加到图像中的一些约束而引起的视图 –

+0

尝试添加4个约束,1为固定宽度,1为固定高度,1为前导空间,1为顶部空间 –

+0

https://dl.dropboxusercontent.com/u/87285547 /constraints.png –

回答

2

您的问题可能是由您添加到imageView的一些限制引起的。尝试添加仅4约束,1固定宽度,1为固定高度,1为顶部空间前导空格和1,你可以看到下面的截图:

enter image description here