Fitting Button's Title Label to the Button

Hello! I'm fairly new to Xcode. I've set up some buttons to scale up with screen size. When the buttons scale, the text within doesn't scale up along with it. I added this code:


           
            button.titleLabel?.numberOfLines = 0;
            button.titleLabel?.adjustsFontSizeToFitWidth = true;
            button.titleLabel?.lineBreakMode = NSLineBreakMode.byClipping;


Now, I set the default text in the story board to the largest value for iPad 12.9".


The text scales properly down to smaller devices, but now there is a space above the text that increases as the device size decreases (iPad 12.9" has no space, iPhone 4s has large space).


https://imgur.com/a/i6mHZpX


This image was taken on the iPhone 8. You can see that the text's font has shrunk perfectly, but it is offset on the Y axis somehow. How can I center the text amongst the button again?

Replies

Did you check in the Attributes inspector for the button, in Control section that the vertical alignment is centered ?