Custom fonts can make all of the difference in the world if you ' re trying to convey a specific user experience. Luckily, it's pretty easy-to-add your own fonts in your IOS app but there is some common pitfalls to watch out for.
Let's walk through how to add custom fonts to your IOS application and I ' ll highlight the common mistakes as we go.
article CONTENTS
1.Include your fonts in your XCode project
2.Make sure this they ' re included in the target
3.Double Check that your fonts is included as Resources in your bundle
4.Include your IOS custom fonts in your application plist
5.Find the name of the font
6.Use Uifont and specify the name of the font
Make sure has a proper font license for Mobile/app embedding.
A Commenter in the discussion below, Stephen, brought up the valid point. The license can usually is found with your font download or on the site where you bought/downloaded it. Taking a minute to check it ensures your won ' t get into legal trouble down the road.
Step 1:include your fonts in your XCode project
most commonly, you'll have a TTF or OTF font so you'll want to use with all of the your uilabels or uitextviews in your app . Well, the first step was to include these fonts into your XCode project.
I commonly keep all of my apps resources such as images or fonts in their own directory called "Resources". I find that this helps me stay organized as projects get much more complex and there is a lot of files. Whatever your case is, either drag and drop your font file (s) into your XCode file tree or right click and "Add Files To ... "To select your fonts.
Make sure, the target you want, use your, font in is checked!
Step 2:make sure that they ' re included in the target
The next thing to do are to make sure, they ' re resources and included in your build target, you want to use the Fon TS in.
Make sure, the target you want, your font in is checked under "Target Membership"
Step 3:double Check that your fonts is included as Resources in your bundle
This is should not being a problem but sometimes if you have trouble getting your font face to show up, this can be a sou Rce of headache So let's double check now-to-rule it out as a potential pitfall.
This can is a source of headache
Go to your project Build phases pane by highlighting the XCode project file with your Solution Explorer and on the right Han D side, select "Build phases". You'll see that one of the sections can expand are "Copy Bundle Resources". Open that list and make sure that your fonts is included in the that list.
Ensure that your fonts is in the "Copy Bundle Resources" list
Step 4:include your IOS custom fonts in your application plist
the next thing to does is to modify your app's plist to include these font faces. By default, your plist is named something like [Appname]-info.plist and would reside in the ' Supporting Files ' folder If you haven ' t moved it.
Open it and add a new row called "Fonts provided by Application" which'll be is an array so you need to add all the Filen Ames of the fonts you want. In my case, it is three of the Neutraface 2 Display fonts as can see in the screenshot below. Be careful to include the extension and make sure so you don ' t perform any typos here. That's another common problem, as simple as it may seem.
See the above screenshot on the key so need to add, followed by the filenames of the fonts your want to include in Yo ur iOS app
... make sure so you don ' t perform any typos here. That ' s another common problem
Step 5:find The name of the font
this is a common pitfall for many people trying to include custom fonts into their IOS app. This is something that eluded me before as well and it's the fact that when you specify which font you want to use, you ' r E not specifying the file name but rather, the font name . The tricky part is, the font name may isn't a is, what are you expect. It could is very different than any of the visible font names so can see.
So in order to easily find the name of the "the" and "want to use", you can output something to the console window and S EE for yourself.
The tricky part is, the font name may isn't a what's expect
Add This snippet of code to log all the fonts available to your apps in the console.
for (nsstring* Family in [uifont familynames])
{
NSLog (@ "%@", family);
for (nsstring* name in [uifont fontnamesforfamilyname: Family])
{
NSLog (@ "%@", name);
}
}
Once you run your app, you'll get the list of fonts displayed in your console log. Then it just a matter of finding your custom font in the list and getting the font names.
Logging all fonts and finding the font names for your custom font
In the screenshot above, as can see the font name I needed is neutraface2display-bold. This font name is no where to is found in the font properties or from the OSX font viewer. Remember to get rid of this code snippet after your find the font name that you need!
Step 6:use Uifont and specify the name of the font
And finally, you can simply display your the custom font using Uifont and whatever UILabel or text view you want.
UILabel *label = [[UILabel alloc] initwithframe:cgrectmake(0, 0, self. View. frame. size. width, )];
label. TextAlignment = Nstextalignmentcenter;
label. text = @ "Using Custom Fonts";
label. Font = [uifont fontwithname:@ "neutraface2display-titling" Size:];
Sample of using custom fonts in your IOS app!
I hope that this IOS custom fonts tutorial is helpful to you. Let me know in the comments below!
Using a custom font in an iOS project