Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom font doesn't work

I'm trying to add a font into my project to use in a label but it just don't work. Here is what I'm doing:

  1. I copy the font file into my project resources.

  2. Set my plist file with the array key UIAppFonts.

  3. Add my font's name Kingashandwriting.ttf (the real name with the extension , not the file name) into the array.

  4. Set up my font in the code: UIFont *font= [UIFont fontWithName:@"Kingashandwriting" size:15];

  5. Set it into my label: [self.myLabel setFont:font];

myLabel is an IBOutlet that is linked with a label in interface builder. I'm using Xcode 4.3.3

Am i missing something?

like image 690
douglasd3 Avatar asked Aug 06 '26 12:08

douglasd3


1 Answers

I remember that I ran into this same problem when implementing custom fonts into my application. I thought that I had the official name right but it was giving me problems.

My advice is to open up the file in font book and look at the top of the window and see what that name says. Then format it exactly how you see it in your fontWithName: method.

Here's an image of what you're looking for:

https://i.sstatic.net/uOZy6.png

Then your font method would look like this (based on the font in the image):

UIFont *font= [UIFont fontWithName:@"BankGothic Lt BT" size:15];

For further information, in my application my file is named bankgthl.ttf and I have that file name added into my plist array. But when I am setting the font in my code I call it the same as above using the name seen in font book and it is all working fine.

like image 57
RGullotti Avatar answered Aug 08 '26 03:08

RGullotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!