Swift 5 Migration has Changed Circular Images

I have a table view controller with many table view sections. In each table view section, there is a table view cell. In each table view cell, there is a content view. In each content view, there is some text and an imageView. The image view is a round profile picture with border. It has always worked. This is the code for each image view:


self.imageView1.layer.cornerRadius = self.imageView1.frame.size.width / 2;

self.imageView1.clipsToBounds = true;

self.imageView1.layer.borderWidth = 2.0

self.imageView1.layer.borderColor = UIColor.white.cgColor

I just migrated to Swift 5, and the circles are now square. No coding changes have been made whatsoever. In fact, when I migrated, the changes that it showed that it would make shouldn't have interfered at all with the roundness of the image.

I am at an utter loss as to how to correct it.

Replies

Well, nothing suggested here or stackoverflow worked. I racked my brain for days...nothing. Finally gave up and decided to just remove it from the next version of the app. While doing this, I decided to try one more thing and it worked. In this line of code:


self.imageView1.frame.size.width / 2;


I started making the number 2 a smaller number. When I got to 0.6 the image was perfectly round again. I have no idea why everything worked perfectly using 2 before the Swift 5 migration...nothing was chnaged. I am just glad I finally got it to work. Thanks to all for your suggestions.

In viewDidLoad, layout has not yet been performed. Frames are usually whatever they were on the storyboard/xib but in reality you should not rely on them having any meaningful values there. It would be better to do that setup after layout, such as in viewDidLayoutSubviews.


Maybe if everything is statically sized this isn’t the real issue in your case; I don’t know. But it’s a bad habit to get into.