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?
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.
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:
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With