0

I am trying to set bold font for UILabel as follows :

lblActivities.font = [UIFont fontWithName:@"sans-serif-Bold" size:15.0];  

But this is not appearing as bold.
Any suggestions?

Nitish
  • 13,845
  • 28
  • 135
  • 263
  • used NSAttributedString for this – SGDev Jan 13 '15 at 09:12
  • @SumitGarg : But how to set all : font name, bold and size? – Nitish Jan 13 '15 at 09:16
  • 1
    Are you sure that's the correct font name? Check against font family names in applicationDidFinishLaunching and it will display exactly the name. It might not need the hyphens for example – soulshined Jan 13 '15 at 09:20
  • 2
    i don't see that font as being available. should also note you can add your own font in if you have your heart set on a particular one. – myte Jan 13 '15 at 09:28
  • sans-serif is not a system font that is reason.try `helvetica-bold` – SGDev Jan 13 '15 at 09:35
  • @SumitGarg : So is helvetica same as sans-serif ? – Nitish Jan 13 '15 at 10:06
  • both are font name but sans-serif not is a predefine font name but helvetica is predefine font name in xcode. – SGDev Jan 13 '15 at 10:18
  • @SumitGarg : I applied helvetica instead. But the fonts are different. – Nitish Jan 13 '15 at 10:31
  • see my edited answer, you have to download sans-serif.ttf file for your font and follow step which was describe in provided link that's it. – Dipen Chudasama Jan 13 '15 at 10:33
  • helvetica just a example. – SGDev Jan 13 '15 at 11:29
  • san serif font just means "without serifs", serifs being the little "tails" added to the characters like in a serif font (e.g. Times Roman). Generally the "default" sans-serif font is Helvetica, but sometimes arial. Have you tried just [UIFont boldSystemFontOfSize:15] ? that's usually a bold san serif font. – Mike M Jan 13 '15 at 12:08
  • check font family in font book and add this code `lblActivities.font = [UIFont fontWithName:@"fontFamilyName" size:15.0];` – Sam Jan 13 '15 at 13:11

3 Answers3

2

1-You need your font in .otf or .ttf copied to your project. For example in Supporting Files.

2 - You need to edit .plist file.

3 - Add "Fonts provided by application" key into your plist and in Item 0 copy the exact filename of the font you copied to your Supporting files WITH extension. For example: "JosefinSansStd-Light_0.otf"

4 - Make sure that the font you imported to your app is being packed into app itself. Do that by selecting your Target, then Build Phases, then Copy Bundle Resources. If you don't see your font in there, drag it from Supporting Files.

5 - Finally, you would like to list all your fonts when the app starts just to see useable name for your font. You will do that with this little piece of code:

NSArray *fontFamilies = [UIFont familyNames];
for (int i = 0; i < [fontFamilies count]; i++)
{
 NSString *fontFamily = [fontFamilies objectAtIndex:i];
 NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
 NSLog (@"%@: %@", fontFamily, fontNames);
}

Search for your font in printed results, for example, I would search for "Josefin" and I would see that actual font name is "JosefinSansStd-Light". After that you only need to use that font by:

UIFont *customFont = [UIFont fontWithName:@"JosefinSansStd-Light" size:20];

In iOS8 you add your fonts directly to the project and they are visible in the interface builder. Modify your code to account for this but programmatically setting font for iOS7 and selecting it in xCode6 interface builder. PS. Interface builder in xCode6 gives you the correct font name that you can copy-paste into the code below.

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

if(SYSTEM_VERSION_LESS_THAN(@"8.0"))
   {
       UIFont *customFont = [UIFont fontWithName:@"OpenSans-Light" size:32];
       self.registerLabel.font = customFont;  
   }

Hope this helps, cheers.

For More Information check This Post

iAhmed
  • 6,556
  • 2
  • 25
  • 31
0

you have direct option in Xcode 1. select the label on view controller 2. on your right hand side panel select attribute inspector . 3. select font text-box link 4. a alert box appear select font dropdownlist 5 select custom from that list 6 set your style bold from style dropdown

-1

try this may be help you. Make sure the font name is correct or available in your application.

[lblActivities setFont:[UIFont fontWithName:@"sans-serif-Bold" size:15.0]];

The Font which you describe is not available in apple library by Default you have to use custom font for this.

see Below link

Using custom font in a UIWebView

Community
  • 1
  • 1
Dipen Chudasama
  • 3,063
  • 21
  • 42