質問

I am having trouble adding this custom font:

[totalRecordedText setFont:[UIFont fontWithName:@"LiberationMono-Bold" size:19]];

I have added a file to my project called "LiberationMono-Bold.ttf". How do I now link the font file to the reference? Right now, it is not displaying the font (it just uses a system default).

Note that this does work by contrast:

[totalRecordedText setFont:[UIFont fontWithName:@"ProximaNova-Bold" size:19]];
役に立ちましたか?

解決

The .ttf file name may or may not be the same as the actual font name. This is what I do to find the real name of the font I want to use

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

This will print out all the fonts that are supported by your system in a dictionary fashion, the Font-family name being the key. Find the key of your desired font and you will see all the sub-fonts in that key. Use that name in the command

[totalRecordedText setFont:[UIFont fontWithName:<actual_font_name> size:19]]; and you should be good. !!

~ Happy Coding

他のヒント

Use this example

UIFont *font = [UIFont fontWithName:@"MyFont" size:20];
[label setFont:font];

Where "MyFont" would be a TrueType or OpenType file in your project (sans the file extension), and label would be an instance of UILabel.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top