Hiho,
I am trying to set a font for my label, but it just doesn't appear in my iOS-Simulator when I run the app.
_textLabel1 = [[UILabel alloc] initWithFrame:CGRectMake((CGFloat) (self.view.center.x - (self.view.bounds.size.width / textWidth / 2)),
(CGFloat) (self.view.center.y * textPositionY), (CGFloat) (self.view.bounds.size.width / textWidth), (CGFloat) textHeight)];
_textLabel1.numberOfLines = 0;
_textLabel1.textAlignment = NSTextAlignmentCenter;
_textLabel1.textColor = clr;
_textLabel1.text = @"Favoriten";
[_textLabel1 setFont:[UIFont fontWithName:@"assets/fonts/Kingthings_Trypewriter_2.ttf" size:36]];
[_favouriteViewer addSubview:_textLabel1];
_textLabel1.font=[_textLabel1.font fontWithSize:25];
I also added the custom font in my plist:
<key>UIAppFonts</key>
<array>
<string>Kingthings_Trypewriter_2.ttf</string>
</array>
I saved my custom font in the named asset folder wich I called in:
[_textLabel1 setFont:[UIFont fontWithName:@"assets/fonts/Kingthings_Trypewriter_2.ttf" size:36]];
I does not show the font in the simulator.
Thanks for the help!
Edit: I am using AppCode, not Xcode.
Edit2:
Thanks to Ganesh Somani, I used his code to try to find out if my font is correctly added to the project via the Copy Bundle ressources but unfortunately it is still not showing up in the log.
for(NSString *fontfamilyname in [UIFont familyNames])
{
NSLog(@"Family:'%@'",fontfamilyname);
for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])
{
NSLog(@"\tfont:'%@'",fontName);
}
NSLog(@"---");
}
Solution: For some reason I had two .plist files in my project. I put in the following code and now it works:
<key>UIAppFonts</key>
<array>
<string>"fontName.ttf"</string>
</array>
Thanks to all contributers for the help!
Just import your font files to your project:
Then add them to your Info.plist file:
Then you can use them in your code:
Make sure you use the correct name, in the font application (after clicking twice and installing your font in your computer, you can see this information) tap CMD + i, and check the "PostScript name" of your font, that is how you will call it.
Open your project on Xcode, tap on the project icon, select the target, then Build Phases, go to the section Copy bundle resources and check if your fonts are there (remember that you need to add them to your project folder):
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