Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios swift 3 xcode8 beta rounded imageView

Tags:

ios

swift3

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

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

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

like image 797
Ali Akkawi Avatar asked Aug 15 '16 11:08

Ali Akkawi


1 Answers

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()

before your code:

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

OR

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

override func viewDidLayoutSubviews() {

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

}
like image 184
pedrouan Avatar answered Oct 18 '22 16:10

pedrouan