Reputation: 4755
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
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
Reputation: 477
Swift 4+
button.titleLabel?.font = UIFont.systemFont(ofSize: 22.0, weight: .bold)
Upvotes: 5
Reputation: 1173
1) Click the button you want to bold the text then find Attributes Inspector.
2) After you press the 'Font'. It will pop out something like this image below.
3) Press the style and choose "Bold".
4) Click Done
and it's done.
Upvotes: 1
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