layer.cornerRadius not working in conjunction with NSLayoutConstraints (swift 3) layer.cornerRadius not working in conjunction with NSLayoutConstraints (swift 3) xcode xcode

layer.cornerRadius not working in conjunction with NSLayoutConstraints (swift 3)


profileImageView.frame.width is zero, because of it's frame isn't calculated yet. Inside your profileImageView override layoutSubviews method:

override func layoutSubviews() {    super.layoutSubviews()    layer.cornerRadius = bounds.width / 2.0}

Or if you're using view controller, override viewDidLayoutSubviews method:

override func viewDidLayoutSubviews() {    super.viewDidLayoutSubviews()    profileImageView.layer.cornerRadius = profileImageView.bounds.width / 2.0}


profileImageView hasn't been laid out yet and doesn't have a size. Presuming this is in a UIViewController subclass, you can put the corner radius code inside viewDidLayoutSubviews:

override func viewDidLayoutSubviews() {    profileImageView.layer.cornerRadius = (profileImageView.frame.width / 2)}