Home / IOS Development / ios – Problems with rounded corner buttons being cut off

ios – Problems with rounded corner buttons being cut off



I have a custom button class I use to get rounded corners. The class works for some hardcoded lengths / widths, but does not work for others. I have not been able to make it work at all with dynamically large buttons. As you can see in the picture, the button is cut off in different ways. Any idea what I̵

7;m doing wrong?

class CustomButton: UIButton{
    
     
       override init(frame: CGRect) {
           super.init(frame: frame)
           setupButton()
       }
       
       
       required init?(coder aDecoder: NSCoder) {
           super.init(coder: aDecoder)
           setupButton()
       }
       
       
       func setupButton() {
           setTitleColor(.white, for: .normal)
           layer.cornerRadius   = frame.size.height/2
           layer.masksToBounds = true
       }
       
}

enter image description here

Thanks for all the help.


Source link