UIFont fontWithName font name
Ios5UifontIos5 Problem Overview
Say you want a specific font for UIFont. How do you know what it's called?
E.g. if you wanted to use this code:
[someUILabelObject setFont:[UIFont fontWithName:@"American Typewriter" size:18]];
From where do you copy the exact phrase "American Typewriter". Is there a header file in Xcode?
UPDATE
Also found this handy.
Ios5 Solutions
Solution 1 - Ios5
Might be interesting for you as Quick Win within the Debugger:
(lldb) po [UIFont fontNamesForFamilyName:@"Helvetica Neue"]
(id) $1 = 0x079d8670 <__NSCFArray 0x79d8670>(
HelveticaNeue-Bold,
HelveticaNeue-CondensedBlack,
HelveticaNeue-Medium,
HelveticaNeue,
HelveticaNeue-Light,
HelveticaNeue-CondensedBold,
HelveticaNeue-LightItalic,
HelveticaNeue-UltraLightItalic,
HelveticaNeue-UltraLight,
HelveticaNeue-BoldItalic,
HelveticaNeue-Italic
)
November 2018 - Update A new swift-y reference for "Custom Fonts with Xcode" - by Chris Ching. I had to update, as this is a great value posting for the new way combined with all missing parts to use custom fonts in a project.
Solution 2 - Ios5
The documentation for UIFont
is pretty clear on this:
> You can use the fontNamesForFamilyName:
method to retrieve the
> specific font names for a given font family.
> (Note: It is a class method)
You can get the family names like this:
NSArray *familyNames = [UIFont familyNames];
Solution 3 - Ios5
label.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:17];
Solution 4 - Ios5
Try
NSArray *familyNames = [UIFont familyNames];
[familyNames enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
NSLog(@"* %@",obj);
NSArray *fontNames = [UIFont fontNamesForFamilyName:obj];
[fontNames enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
NSLog(@"--- %@",obj);
}];
}];
Solution 5 - Ios5
I made a library to solve this problem:
https://github.com/Nirma/UIFontComplete
All fonts are represented as a system Font
enum and the library also details a way of using it with your custom fonts in the read me.
Basically this:
let font = UIFont(name: "Arial-BoldItalicMT", size: 12.0)
Is replaced with either this:
let font = UIFont(font: .arialBoldItalicMT, size: 12.0)
Or this:
let myFont = Font.helvetica.of(size: 12.0)
Solution 6 - Ios5
This is how you get all font names in your project. That's it ... 3 lines of code
NSArray *fontFamilies = [UIFont familyNames];
for (int i=0; i<[fontFamilies count]; i++)
{
NSLog(@"Font: %@ ...", [fontFamilies objectAtIndex:i]);
}