简体   繁体   中英

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.

After fontWithName you have to use boldSystemFontOfSize:

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

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.

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]; 

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];

您始终可以为按钮创建正常和选定状态图像,并使用它们来创建您想要实现的外观。

在斯威夫特 5

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM