Snorlax
Snorlax

Reputation: 4755

Swift: Bolding UIButton


Is it possible to bold the font in a UIButton? With label, it's pretty simple such as:

label.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)

But this doesn't work for buttons.

Upvotes: 9

Views: 21591

Answers (4)

Sagun Raj Lage
Sagun Raj Lage

Reputation: 2494

In iOS 15, you have to change the font size and weight using UIConfigurationTextAttributesTransformer. The sample code is given below:

someButton.configuration?.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
                var outgoing = incoming
                outgoing.font = UIFont.systemFont(ofSize: 16, weight: .bold)
                return outgoing
            }

Upvotes: 3

dbrownjave
dbrownjave

Reputation: 477

Swift 4+

button.titleLabel?.font = UIFont.systemFont(ofSize: 22.0, weight: .bold)

Upvotes: 5

kit
kit

Reputation: 1173

1) Click the button you want to bold the text then find Attributes Inspector.

Attributes Inspector

2) After you press the 'Font'. It will pop out something like this image below.

"something pop out"

3) Press the style and choose "Bold".

4) Click Done and it's done.

Upvotes: 1

ciccioska
ciccioska

Reputation: 1291

For a UIButton I tried this and works:

Swift 2

testButton.titleLabel?.font = UIFont.boldSystemFontOfSize(18)

Swift 3 & 4

testButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 18)

(Thank's to ConfusionTowers)

Upvotes: 32

Related Questions