The problem is that you are running this code too soon (in viewDidLoad). Your cornerRadius calculation depends upon calculateButton.frame, but its value is not known at this time. Move your code into viewDidLayoutSubviews and I think you will find that it works as you expect.