Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a bold version of UIFont's prefferedFontForTextStyle?

Tags:

ios

In iOS 7, users can manipulate their fonts from the control panel, something designed to help (amongst other things) visually impaired users.

I'm trying to work with the new paradign by using the new methods created to support that functionality. For the most part, it's easy enough -- just use [label setFont:[UIFont prefferedFontForTextStyle:UIFontTextStyleHeadline]] or whatever format you need.

But occasionally I need to adjust those. For example, maybe headline needs to be a bit bigger. I can use this answer to that. Unfortunately, I can't figure out how to apply that answer to other changes, such as simply bolding the font without changing the size.

like image 410
RonLugge Avatar asked Oct 09 '13 23:10

RonLugge


1 Answers

You can try this:

UIFontDescriptor *descriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleHeadline];
/// Add the bold trait
descriptor = [descriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
/// Pass 0 to keep the same font size
UIFont *font = [UIFont fontWithDescriptor:descriptor size:0];
like image 55
Hejazi Avatar answered Oct 12 '22 12:10

Hejazi