I'm trying to make images circular and for some reason the below code is creating a diamond-shaped photo:
profilePicture.layer.cornerRadius = profilePicture.frame.size.width / 2
profilePicture.clipsToBounds = true
How do I make it round? Thanks!
It's displaying a diamond shape because you're setting the cornerRadius before the the size of the view changes.
This would result in a diamond shape:
var myView = UIView(frame: CGRect(x: 10, y: 10, width: 100, height: 100))
myView.backgroundColor = UIColor.redColor()
view.addSubview(myView)
myView.layer.cornerRadius = myView.frame.size.width / 2
// setting frame doesn't change corner radius from the former large value
myView.frame = CGRect(x: 50, y: 50, width: 50, height: 50)
You can set this immediately before the view is displayed by doing so in viewWillAppear:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With