Using custom fonts in interface builder
I have also this problem in Xcode 4. In my program, there are lots of UILabel
which have no IBOutlets
so I do in that way;
First, subclass the UILabel
to CustomFontLabel
Then, override the "awakeFromNib
" method
@implementation CustomFontLabel
- (void)awakeFromNib {
[super awakeFromNib];
self.font = [UIFont fontWithName:@"CustomFontName" size:self.font.pointSize];
}
@end
Finally, in Interface Builder > Identity Inspector change class to CustomFontLabel
.
LaunchScreen.xib not displaying my custom font
There's no big surprise here. The launch screen is shown at launch time - actually, before launch time - so the font probably hasn't yet loaded.
You could file a bug if you think you have a compelling use case. But I don't really think you do. Why are you showing any text in your launch image? It should be much more bare-bones than that - just enough to give the structure of the opening interface, which will be filled in when the opening interface actually appears. A "blank" screen with the same background color as the initial view controller's background color would be sufficient. You goal is just to provide an alternative to blackness.
Xcode 8 custom font doesn't show up in interface builder
Try Below Steps: Code tested in Swift 3
.
Step 1: Add Your custom font into your project( Make sure Add to Target
ticked).I am using "PermanentMarker.ttf","Pecita.otf" and "AROLY.ttf" font as a test font.
Note: Supporting font Type ttf and otf (Both font types should work)
Step 2: Modify the application-info.plist file.
Add the key "Fonts provided by application" in a new row and add "PermanentMarker.ttf" as new item in the Array "Fonts provided by application".
Your plist should looks like this
Now the font will be available in Interface Builder. To use the custom font in code we need to refer to it by name, but the name often isn’t the same as the font’s filename
Now, You can access the Custom Font from your viewController. I am testing the font by placing a UIlabel to the Storyboard like below.
Update 2: Working Solution
After, imported your custom font and updated your plist
.selectlabel
from your storyBoard
,goto Attributes Inspector
under Label
>Text type
> select to Attributed
and choose your custom font
from the list.
Output:
Update 1
If your custom font still not listed in Xcode font list
.check the related link to your issue
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
custom font not displaying on some simulator
Note: Still,You can assign BebasNeue
or custom font
programatically to your label or button etc. even its not showing in your interface Builder
.If you having trouble setting font to your object programatically.try below method.
Assign font to UILabel:
label?.font = UIFont(name: "BebasNeue", size: 35) // Set to any size
Assign font to UIButton:
button.titleLabel?.font = UIFont(name: "BebasNeue", size: 35)
Assign font to UITextField:
textField.font = UIFont(name: "BebasNeue", size: 25)
Assign font to UINavigationBar:
navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "BebasNeue", size: 25)!, NSForegroundColorAttributeName: UIColor.red]
Assign font to UIToolBar:
UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: "BebasNeue", size: 25.0)!], for: UIControlState.normal)
Output:
Custom fonts in Interface Builder
Yes, Marrius is right. In Xcode 6, you neither need to use extra software nor to set Font in Code files. Just add your font files in your project along with other files. And Interface builder will display the added fonts in the Custom Font List.
And the most amazing thing is, xcode 6 shows the applied font instantly in IB. This is the great addition by Apple.
Also make sure to add this key "Fonts provided by application" in your project's info.plist and provide your font file names to see the effect in devices.
How to set font to the label in launch Screen in iOS 8
Even though it may appear like you can in Xcode 6, you can't specify a custom font for the launch screen, since the launch screen is shown before your fonts load. Create an image of your text and use that.
Xcode 7.2.1 Custom font in Interface bulilder
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.
Custom Font is not working in iOS 8
I found the cause of the "missing" fonts. In fact the font is still there, but from iOS 7 to iOS 8 the font name had a subtle but abrupt change: in iOS 7 it is called, e.g. "Custom_Font-Style", but now in iOS 8 it is called "Custom-Font-Style". Notice the underscore between Custom and Font now changes to dash. Fortunately the font family name remains the same, as "Custom Font Family", so now instead of hard-coding the font name I have to extract it out from the font family, like this:
static NSString *_myCustomFontName;
+ (NSString *)myCustomFontName
{
if ( !_myCustomFontName )
{
NSArray *arr = [UIFont fontNamesForFamilyName:@"Custom Font Family"];
// I know I only have one font in this family
if ( [arr count] > 0 )
_myCustomFontName = arr[0];
}
return _myCustomFontName;
}
I'm not sure how a font file presents its information, but now I guess my font file (custom font.ttf) only provides a font family name "Custom Font Family", and iOS derives its font name from certain rule, which for some reason changed from iOS 7 to iOS 8, so before we had Custom_Font-Style, now we have Custom-Font-Style.
Related Topics
How to Add Headerview in Uicollectionview Like Uitableview's Tableheaderview
Change Order of Read Items with Voiceover
Cagradientlayer Diagonal Gradient
How to Change the Uisearchbar Search Text Color
How to Add Constraint Between a View and the Top Layout Guide in a Xib File
Uiscrollview's Origin Changes After Popping Back to the Uiviewcontroller
What's Dead & Exploded in Swift's Exception Stack
Facebook Share Content Only Shares Url in iOS 9
Creating a 3X3 Grid with Auto Layout Constraints
How to Use Device Instead of Simulator
No Such File and Directory Found Xcode 7
How to Parse This JSON in Swift
Why I Couldn't Assign Fetched Values from Firestore to an Array in Swift
How to Use Git Properly with Xcode
How to Change the Image Displayed in a Uiimageview Programmatically