How use custom font with label in Xcode 7.1.2? I created a group and added my fonts files into project. In interface builder chose custom font, family and style(Acrom ExtraBold 20.0). In IB all looks fine, but not in simulator - displays system default font. Also I've added 'Fonts provided by application' array with list of my fonts files to Info.plist and installed font on the machine.
1 Answers
Final Edit:
If you don't mind, I'll reword your question as I understand it much better now that you've kindly supplied me with your project.
In short your question is this:
My custom font does not work in my launch storyboard despite the fact that it works elsewhere in the main app. How can I make it work in the launch screen?
It appears that you can't use custom fonts in a launch screen as they haven't yet been loaded. There are a number of answers on Stack Overflow confirming this. See here, here and here.
My advice would be to either avoid using the fonts in the storyboard or use them as an image.
Let's go through a number of the steps one-by-one to see if we can pinpoint the problem here.
Step 1. In your plist
have you included the fonts under UIAppFonts
aka Fonts provided by application
? Like this:
Step 2. Also, have you made sure that the correct targets are selected? Like this:
Step 3. Also, try running this to see if your fonts are listed. If not then make sure they are spelled exactly as the filenames.
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSLog(@"Fonts: %@", [UIFont familyNames]);
Step 4. Another also - check the Font Book application on your mac, search for the font and find its correct name. Like this:
Step 5. Then check that the font is included in the bundle resources for the project like this:
Step 6. And finally double check that you selected to copy the fonts to the bundle when you added them to your project, like this:
Edit
It seems that the font works for you iff you refer to it in code but not if you refer to it using IB. So maybe...
Step 7. Delete the app from the simulator, clean the project and then rebuild.
-
Yes what? Try running the above code logging all of the family names. Do you see your font there? – Gordonium Mar 06 '16 at 19:13
-
Also, I'd advise against naming the fonts `The.Northern.blah.blah.ttf`. Instead try `The-Norther-blah.ttf` so that the only `.` is before the extension. – Gordonium Mar 06 '16 at 19:15
-
1All fonts listed! Now I'm trying with STJEDISE.TTF according this guide - https://grokswift.com/custom-fonts/, no success.. – ViES Mar 06 '16 at 19:29
-
So you're saying that the font is listed when you log it using the above code but it doesn't appear in Xcode after you've selected custom font on the attributes inspector? Can you double check that the target is included? – Gordonium Mar 06 '16 at 19:32
-
It's appearing in xcode IB (I can select all my fonts ant styles for them), but not in simulator.. Now I'm try to programmatically set font, for table cell: `cell.textLabel?.font = UIFont(name: "StarJediSpecialEdition", size: 16)` and seems it's works.. – ViES Mar 06 '16 at 19:43
-
Woah. So you're saying that it works if you set it in code but it doesn't work if you select it in IB? – Gordonium Mar 06 '16 at 19:47
-
Exactly! And problem is I don't know how to set font for label on LaunchScreen.storyboard programmatically.. – ViES Mar 06 '16 at 19:51
-
OK. I've added another check in my answer to see if the font is copied into the app's bundle. Could you check that and see if the font is there? – Gordonium Mar 06 '16 at 19:55
-
To make it clear. Try Step 5 above. Then let me know if you did Step 6 when you added the font(s)? – Gordonium Mar 06 '16 at 20:02
-
Maybe step 7? I'm grasping at straws here if you can't tell. :) – Gordonium Mar 06 '16 at 20:10
-
Tried, no luck.. Can you test it on your machine with 'single view application' project on swift? – ViES Mar 06 '16 at 20:47
-
I've used custom fonts a number of times. Almost always been fine. I think if you shared your project with me via dropbox or something similar then I could take a proper look? – Gordonium Mar 06 '16 at 20:50
-
I'll be grateful. I created a github repo: https://github.com/ViieeS/SwiftTests.git – ViES Mar 06 '16 at 21:23
-
I've checked it out and confirmed what you're saying. And I've updated my answer. If it helps, let me know – Gordonium Mar 06 '16 at 21:42