nirav
nirav

Reputation: 651

Change Button Title in iOS 15

I am using new button configuration style as introduce in iOS 15. It works great!

But when I try to change the title, it is also change the font.

Ref similar issue: uibutton.setTitle change text without changing font size

I don't want to go back to old style :(

My try:

var config = self?.btnNext.configuration
    config?.title = "New Title"
self?.btnNext.updateConfiguration()

Thank you,

Upvotes: 1

Views: 631

Answers (1)

H. Wallace
H. Wallace

Reputation: 23

Try using an attributedTitle so you can set the font:

config?.attributedTitle = AttributedString("your new title", 
attributes: AttributeContainer([
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20.0), NSAttributedString.Key.foregroundColor: .black]))

Hope this helps.

Upvotes: 1

Related Questions