0

I have, in starting to programmatically develop a screen, the following:

NSInteger offset = 0;
UIFont *font = [UIFont fontWithName:@"Scurlock" size:80];
UILabel *label = [[UILabel alloc] initWithFrame:(CGRectMake(20, 40 + offset, width, 20))];
[label setFont:font];
[label setText:@"Hello, world!"];
[self.view addSubview:label];

The "Hello, world!" does appear at the intended coordinates, but I have not found a way to change either the font family or font size. Scurlock is a TrueType font included in the app's resources.

How can I say "Display this text in that font at these coordinates" with a UILabel or something comparable like an RTLabel (which I managed to get bold, but not change the font or font size)?

--EDIT--

I have Scurlock.TTF at the top of Supporting Files and the following from the plist:

<key>Fonts provided by application</key>
<array>
    <string>Scurlock.TTF</string>
</array>

This results in one 0 in the list printed out for one answer, and the behavior is AFAICT the same whether I specify Scurlock or Scurlock.TTF.

Christos Hayward
  • 5,777
  • 17
  • 58
  • 113
  • 4
    Are you sure the font's name is really "Scurlock" and not some variant of that? Verify that `font` isn't `nil`. – rmaddy Oct 03 '13 at 14:05
  • Font is nil. I added in Scurlock explicitly to the project (I hadn't--oops), and now opening the font's folder in finder, right-clicking, and selecting "Get Info" gave a name of "Scurlock". – Christos Hayward Oct 03 '13 at 14:19
  • That's the family name, not the font name. – rmaddy Oct 03 '13 at 14:21
  • It isn't working yet. Should I be specifying "Scurlock.TTF Scurlock" somewhere? – Christos Hayward Oct 03 '13 at 15:10
  • Run the code in the answer by Peter and look for a font name (not family name) that comes from your Scurlock TTF file. also make sure your file is really named "Scurlock.TTF" and not "Scurlock.ttf". Case matters. – rmaddy Oct 03 '13 at 15:13
  • I had run that code earlier, and ran it again. It didn't load any form of Scurlock. The code has identical case to the filename (Scurlock.TTF). The font I have is available from http://JonathansCorner.com/project/Scurlock.TTF – Christos Hayward Oct 03 '13 at 15:24

2 Answers2

3

• Check your target under "Copy Bundle Resources" to make sure that the font is actually included in the bundle.

• Add the font to your plist if you haven't yet.

• Double check the font name using

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

See this guide.

Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101
1

Take a look at this: Use custom fonts in iPhone App Look at the .plist property that you add, and make sure it's the same name as the one you are trying to load.

Community
  • 1
  • 1
ivan_yorgov
  • 1,281
  • 1
  • 9
  • 7