Home > Software design >  uibutton.setTitle change text without changing font size
uibutton.setTitle change text without changing font size

Time:02-17

First, I added a button and set it's size to be 40

Then, in ViewController, I will change its text when user tap the button

startStopBtn.setTitle("START", for: .normal)

But not only the title change, the size also changed to 17.

Why is that? I want to keep the size unchanged.

Im using swift 5

enter image description here

enter image description here

CodePudding user response:

iOS 15 introduced Configuration settings for many controls -- including UIButton.

When you create a button using Storyboard / Interface Builder in Xcode 13, the default configuration is Plain. Without changing that, you need to use the options via UIButton.Configuration to change much (most) of the button's appearance.

Selecting Default from the Button Style drop-down gives you a "pre-iOS 15" type of button.

  • Related