3
votes

I want to set the selected label to appear bold without implementing the font family-bold version. Ex:- the default way to set bold is as follows

UIFont *myFont = [UIFont fontWithName:@"Helvetica-BoldOblique" 
                                 size:[UIFont systemFontSize]];

But i want to change the font weight(i.e BOld, Italic or Underline) only. without calling the "fontWithName".

Thanks in advance

4

4 Answers

1
votes

You are out of luck. For non-system fonts, you have to use fontWithName to get to the bold version. From the documentation of UIFont:

fontName
The fully specified name of the font. This name incorporates both the font family name and the specific style information for the font.

Possible workaround:
So, while you cannot have a generic method that would switch every font to bold, you could still implement this by maintaining a set of string constants that you can look up to switch to the correct bold version of the fonts you are using in your app.

1
votes

I recently wrote a blog post about that topic. You can see it at http://eclipsesource.com/blogs/2012/07/26/uifont-from-a-css-definition/

With the code I provide there, you can get your desired UIFont as easy as:

UIFont *myFont = [FontResolver fontWithDescription:@"font-family: Helvetica; font-weight: bold; font-style: italic;"];

0
votes

If you want the system font (Helvetica Neue), you can use boldSystemFontOfSize:. Otherwise you're stuck specifying bold in the font name. See the UIFont reference for details.

0
votes
labelName.font=[UIFont boldSystemFontOfSize:[UIFont systemFontSize]];

Use this statement it will help you