Deepak Chandra
Deepak Chandra

Reputation: 101

How to use custom font in iOS ( Eg: Helvetica CY.ttf ) with Xcode programatically

Any help will be appreciated.

Thanks!

Upvotes: 6

Views: 26382

Answers (5)

christijk
christijk

Reputation: 2243

Apple provides a set of fonts to customize our application and also allow us to add custom fonts.

Steps

  1. Copy the font files(.ttf or .otf) to main bundle.

  2. Add the file names into info.plist as a new array named "Fonts provided by application".

  3. It is very important to add the post script name of fonts into this array. That means each font have the font name(with extension) and its postscript name in info.plist.

  4. To find the Post script name,just open the Fontbook application in mac and then add the font file. After adding the font file into font book just look at the information tab of that font,there we can find the Post script name.

  5. Using is pretty simple, use the post script name of the font,

    nameLabel.font = [UIFont fontWithName:@"HelveticaCY-Plain" size:22];
    

enter image description here

Upvotes: 21

Mohit Padalia
Mohit Padalia

Reputation: 1579

In case someone is interested in Swift 3 code for getting fonts:

for family in UIFont.familyNames
{
    print("Family: \(family)")

    for name in UIFont.fontNames(forFamilyName: family)
    {
        print("Name: \(name)")
    }
}

Upvotes: 0

Niharika
Niharika

Reputation: 1198

just go throw this link and follow steps. it is having all steps http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/

Upvotes: 1

Markus
Markus

Reputation: 1177

I made the same mistake. The key is the answer above:

for (NSString* family in [UIFont familyNames]) {
   NSLog(@"%@", family);

   for (NSString* name in [UIFont fontNamesForFamilyName: family]) {
       NSLog(@"  %@", name);
   }
}

I included in my project folder the GOTHIC.TTF file.

And in my Info.plist I included GOTHIC.TTF in "Fonts provided by application".

But surprise! The font it is not called "GOTHIC", but "CenturyGothic".

[cell.textLabel setFont:[UIFont fontWithName:@"CenturyGothic" size:24]];

Upvotes: 1

Rajesh Loganathan
Rajesh Loganathan

Reputation: 11247

Its simple only. Its working for me in xcode6.1 too.

Try using this steps :

Step 1: Include your fonts in your XCode project

Step 2: Make sure that they’re included in the target

Step 3: Double check that your fonts are included as Resources in your bundle

Step 4: Include your iOS custom fonts in your application plist

Step 5: Find the name of the font

for (NSString* family in [UIFont familyNames])
{
    NSLog(@"%@", family);

    for (NSString* name in [UIFont fontNamesForFamilyName: family])
    {
        NSLog(@"  %@", name);
    }
}

Step 6: Use UIFont and specify the name of the font

label.font = [UIFont fontWithName:@"Helvetica CY" size:20];

Upvotes: 39

Related Questions