Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIFont with custom font fails with Nil

I'm trying to add a custom font to my project in Xcode 4.2, but whenever I try to use it, I get a error that the object is nil.

I have done the following:
1) Added a row to my .plist 'Fonts provided by application' value: "LCDMono2 Ultra.ttf"
2) Added the font to my Supporting Files and showed it in XCode to verify it was added.
3) Verified using Get Info that the Full Name is "LCDMono2 Ultra"
4) Created the font in my project with:

UIFont *myFont = [UIFont fontWithName:@"LCDMono2 Ultra" size:16];

and I've tried this variant:

UIFont *myFont = [UIFont fontWithName:@"LCDMono2 Ultra" size:16.f];

5) Tried to use the font name (addObject:myFont.fontName), generating the 'nil' error.

What could be causing the error? Could it be something like the space in the name?

like image 621
wayneh Avatar asked Jan 28 '12 17:01

wayneh


People also ask

How to add custom fonts to material UI?

Copy the CDN link and add it to the <head> of the public/index.html file: To be able to use the fonts, you’ll have to initialize it using the CreateMuiTheme which is an API provided by Material UI that generates a custom theme based on the options received and ThemeProvider which is a component used to inject custom themes into your application.

How to add a font-family to a Mui theme?

Unzip them, and place them in your project, in the appropriate location src/fonts Like before, you’ll have to define the font-family using the CreateMuiTheme and wrap your components with the ThemeProvider component:

How to use the cormorant and Josefin-Sans fonts in WordPress?

For example, if you want to use the Cormorant font for the heading and Josefin-sans for the button, you’ll first define two themes for the Cormorant and Josefin-sans fonts respectively: Then, wrap target components with a ThemeProvider component of the required font like below: And Viola!


1 Answers

I had this exact same problem for a few hours and tried all of the above and none worked, the font was being added everywhere it should have been and I even tried fonts which worked in other apps, but never appeared to be added to this app.

It appears something has changed in Xcode 5 the font had to be added in the target properties under the info tab for this to work whereas previously they had to be added in the "appName-info.plist' see image below:

Hope this helps someone else.

enter image description here

like image 136
Rich Avatar answered Sep 25 '22 18:09

Rich