简体   繁体   中英

ios swift 3 xcode8 beta rounded 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

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

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM