Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
620 views
in Technique[技术] by (71.8m points)

swift3 - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...