Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

iphone - Cant find custom font - iOS

i have added a custom font - one which i have downloaded from from the net. it is in TTF format and can be used on other programs on my mac. (Successfully added it to font book and used in fireworks).

I have added the key to the info .plist but the font doesn't seem to work.

When i NSLog the font it is null so i am assuming it isn't finding it.

The TTF is called LONDON__.TTF but has a name as London font.

What should i use as the font and add to the info.plist for this to work?

Thanks

Dan

Application fonts resource path = LONDON__.TTF

NSLog(@"%@",[UIFont fontWithName:@"London font" size:22]);

and

NSLog(@"%@",[UIFont fontWithName:@"LONDON__.TTF" size:22]);

Both of them return Null.

Although the file is named LONDON__.TTF the font appear as everyone in Font Book. is this the issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Look at all the available fonts

Objective-C:

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

Swift:

for family: String in UIFont.familyNames() {
    print("%@", family)
    for name: String in UIFont.fontNamesForFamilyName(family) {
        print("  %@", name)
    }
}

..if it's not there, install again

  1. Copy the .ttf file into your project (i.e. drag it to the resource folder in the Project navigator).

  2. In your Info.plist add an entry with the key Fonts provided by application with an Array type. As Item 0, add a String value corresponding to the font file name (e.g. OpenSans-ExtraBoldItalic.ttf).

  3. Make sure the font file is included in the copy bundle resources list under the project settings.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...