简体   繁体   中英

How to use Calibri font?

I want use Calibri font for to display a text in a label. Can any one help how to use Calibri font.

Thanks in advance.

You want to use custom font in your application so first you can add the font in your project bundle then store font in to plist like this way..

     <key>UIAppFonts</key> // Fonts provided by application
<array>
    <string>@“custom font name” </string>
</array>

then you will call this method in to your didFinishLaunchingWithOptions method.

-(void)CustomFont
 {
     for (NSString *familyName in [UIFont familyNames])
     {
         for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName])
         {
              NSLog(@"%@", fontName);
         }   
     }
  }

and final you find your font name and use your custom font.

[label setFont:[UIFont fontWithName:@"Calibri" size:30]];

I hope this will use full to add custom font...

Try This

[label setFont:[UIFont fontWithName:@"Calibri" size:14]];

EDIT:

This Link will give you an idea of about using calibri font in iphone.

All The Best.

To set custom font to your UILabel or any other object needing UIFont you can use

NSString *fontName = @"Calibri";
CGFloat fontSize = 16.0;
myLabel.font = [UIFont fontWithName:fontName size:fontSize];

In order for font to get loaded it should be present in the system and fontName must contain the actual font name, otherwise [UIFont fontWithName: size:] will return nil and you'll get an exception trying to set it as a font to your label.

If you want to use the font that is not present in the system by default (ie it can not available in Interface Builder) you should do the following:

  1. Copy your font files (.ttf or .otf) to your project bundle.
  2. In your Info.plist add parameter "Fonts provided by application" and list font file names in its items
  3. In your app use [UIFont fontWithName: size:] as shown above

This approach works in iOS 3.2 and later. The main trick here is to pass a correct font name which is not always the same as your font file name. Sometimes font name contains modifiers like "black" or something. The rule of thumb here is to double click your font file to launch font preview utility. In Windows font name you should use is typically displayed in the first line. In MacOsX font name is displayed in preview window's caption and you'll probably need to add "-type" to it where "type" is font type shown in dropdown menu.

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