3

I know this subject has been run into the ground, however I have tried every solution I've found on StackOverflow to fix this issue, and its just not working for some reason. I am creating a UILabel programmatically, then using this font. The UILabel is rendering but not in the font I want it to (looks like its defaulting to something)

First I imported two .ttf fonts into the xcode project under a folder called "Resources". The two fonts are Gotham Book and Gotham Book Italic (GothaBoo.ttf, GothaBooIta.ttf)

Then, I added a line to the [my app]-Info.plist file called "UIAppFont", added two rows to the array, Item 0 | String | GothaBoo, Item 1 | String | GothaBooIta.

I checked the Target Build Phases, under Copy Bundle Resources, and made sure the two fonts were in there.

Then, I simply added this code to the viewDidLoad routine:

UILabel *myLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 100)];
myLabel1.text = @"Hello";
myLabel1.backgroundColor = [UIColor clearColor];
myLabel1.font = [UIFont fontWithName: @"GothaBoo" size: 48.0];
myLabel1.textColor = [UIColor blackColor];

[self.view addSubview:myLabel1]; 

No dice. What on earth am I doing wrong? The project is in Xcode 4.3.2, for the iPad, running 5+ of iOS

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
optionsix
  • 956
  • 1
  • 8
  • 27

2 Answers2

5

In the array the full filenames must be provided, so instead of Item 0 | String | GothaBoo, Item 1 | String | GothaBooIta you will have to turn this into Item 0 | String | GothaBoo.ttf, Item 1 | String | GothaBooIta.ttf

Secondly the filename or the fontname might be different than the name that iOS likes to see in fontWithName:. Use Fontbook on your Mac to get the right name, if it still does not work after you have changed the filenames in the .plist.

thvanarkel
  • 1,601
  • 1
  • 12
  • 19
  • This fixed the issue, man could they make this any more obtuse. The real names of the font were Gotham-Book and Gotham-BookItalic. I have one more minor issue though... the font size doesnt seem to want to change. Are there only certain font sizes that are supported with a custom font? – optionsix May 10 '12 at 22:47
  • @optionsix How did you figure it out? Please share , I'm having a similar problem. Thanks! – George Sep 14 '12 at 13:16
1

Beware on the difference of the filename and the fonts name. The fonts name will be found in Fontbook. In info.plist, it's the filename, and in the code, it's the fonts name.

Struggled with this for a long time myself. Pretty sure that would work.

Martol1ni
  • 4,684
  • 2
  • 29
  • 39