2016-11-15 60 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