Reputation: 1205
I'm trying to draw a circular image in a tableview cell. I have figured out how to draw the circle when the image is in a normal view: I place this code in viewDidLayoutSubviews () so as to apply my changes to the image only after autolayout has done its thing.
profilePicture2.layer.cornerRadius = profilePicture2.frame.size.height/2
profilePicture2.clipsToBounds = true
I got that tip from this answer: Why does adding an align with centre constraint to a UIImage throw out the radius of corners setting?
But how do I do it if the image is in a dynamic tableview cell? Is there a way to use viewDidLayoutSubviews() for a single cell, so I can set the corner radius of my image AFTER autolayout has done its thing?
Thanks in advance.
Upvotes: 0
Views: 190
Reputation: 486
You can create a custom class for profilePicture which extends UIView and override layoutSubviews
.
override func layoutSubviews() {
layer.cornerRadius = frame.size.height/2
}
Upvotes: 2