vinothp
vinothp

Reputation: 10069

How to bold the button text in ios?

In my app I am using custom font which working perfectly fine. But I need the button text to be bold. I googled it there is only for System fonts.

Code

button.titleLabel.font = [UIFont fontWithName:@"YanaR" size:20.0]; 

Thanks for your help guys.

Upvotes: 4

Views: 10954

Answers (6)

Divyansh Jain
Divyansh Jain

Reputation: 378

In Swift 5

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

Upvotes: 0

B-Rad
B-Rad

Reputation: 349

You could always create normal and selected state images for your buttons and use those to create the look you are trying to achieve.

Upvotes: 0

Ricardo
Ricardo

Reputation: 2291

After fontWithName you have to use boldSystemFontOfSize:

[button.titleLabel setFont:[UIFont fontWithName:@"Arial" size:13.f]];
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:13.f]];

Upvotes: 10

Adam Levy
Adam Levy

Reputation: 97

Not sure about the YanaR font but if you consider Helvetica font and just wanted to set the font to plain Helvetica you would do:

buttonTitleLabel.font = [UIFont fontWithName:@"Helvetica" size:20.0];

In order to make the font bold all you have to do is append -Bold to the end of the font name like so:

buttonTitleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0];

Upvotes: 0

JAB
JAB

Reputation: 3235

You will also need to include the bold version of the font you are using, if available. It's a totally separate font. If it is available, after you include it, set it the same way you are trying but use the bold font name instead.

for example:

button.titleLabel.font = [UIFont fontWithName:@"YanaR-Bold" size:20.0]; 

Upvotes: 3

Jonathan King
Jonathan King

Reputation: 1528

That's because fonts don't magically make themselves bold. Bold fonts are designed separately. I'm afraid there is no answer to this question, apart from thickening the stroke of the lines, which would probably be in breach of your font agreement.

Upvotes: 4

Related Questions