User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

Q&A is closed


Custom Fonts

Using a custom font in Cocoa touch

There are a lot of fonts provided by iOS. This example will use “Heiti SC”.

Importing a font not provided by iOS

Sample Font: Lobster.otf

1. Copy the font into your project.
2. Go to project info.plist and add the key: “fonts provided by application”. It should be kind of type array.
3. Insert the font as item into the array. The item font-name must be the name of your font-file (here: Lobster.otf).

- (void)viewDidLoad
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    // ** Label with Font Heiti SC (is provided by iOS) **
    UILabel *iOSFontLbl = [[UILabel alloc]initWithFrame:CGRectMake(40.0f, 20.f, 230.0f, 42.0f)];
    iOSFontLbl.font = [UIFont fontWithName:@"Heiti SC" size:14.0f];
    iOSFontLbl.text = @" - Heiti SC";
    [self.view addSubview:iOSFontLbl];
    // ** Label with Font Lobster (is not provided by iOS) **
    UILabel *customFontlabel = [[UILabel alloc]initWithFrame:CGRectMake(40.0f, 80.f, 230.0f, 42.0f)];
    customFontlabel.font = [UIFont fontWithName:@"Lobster" size:8.0f];
    customFontlabel.text = @" - Lobster";
    [self.view addSubview:customFontlabel];

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
objective-c/examples/fonts.txt · Last modified: 2024/02/16 01:06 (external edit)

Impressum Datenschutz