I have been using a specific font which I've been testing on the iPad directly and it was working fine.
Now all of a sudden, the label or textview using the font are default back to Helvetica.
As a hack I'm setting the font manually, but this is ridiculous
self.taskNameView.font = [UIFont fontWithName:#"BradleyHandITCTT-Bold" size:24.0];
Any idea why all of a sudden, interface builder is freaking out?
I've tried cleaning but that didn't help.
I'm on XCode 4 and working on iOS 4.3
If you just want to override all fonts in your application, maybe a category on UIFont will do the trick?
Try adding this to e.g. your AppDelegate.m:
#implementation UIFont (FontOverride)
+(UIFont*) systemFontOfSize:(CGFloat)fontSize
{
return [UIFont fontWithName:#"radleyHandITCTT-Normal" size:fontSize];
}
+(UIFont*) boldSystemFontOfSize:(CGFloat)fontSize
{
return [UIFont fontWithName:#"radleyHandITCTT-Bold" size:fontSize];
}
+(UIFont*) italicSystemFontOfSize:(CGFloat)fontSize
{
return [UIFont fontWithName:#"radleyHandITCTT-Italic" size:fontSize];
}
#end
Related
I'm trying to use setFont on a label, but it seems it doesn't work on iOS > = 8.
I wrote :
UIFont *font = [UIFont fontWithName:#"HelveticaNeue-Light" size:12];
[self->myLabel setFont:font];
Any ideas ?
EDIT : The problem isn't on the font, but on the SIZE. The label stay on the "default" size wrote in the storyboard.
It's because there is no font family with name #"HelveticaNeue-Light" hence size:12 will also not work
And also make sure adjustsFontSizeToFitWidth is disabled with
label.adjustsFontSizeToFitWidth = NO
You can get the available fonts in attribute inspector of Interface Builder
I am creating UILabel, for the label i can set the font name as HelveticaNeue Regular, Light, UltraLight etc, But i unable to set the font name as HelveticaNeue Thin, it is not working as expected. I did like,
label.font = [UIFont fontWithName:#"HelveticaNeue-Thin" size:16];
Also i have searched on Google didnt got any solution. How to fix this issue? Thanks.
This font is bundled with iOS 7, so if you're targeting iOS 7 and above your
label.font = [UIFont fontWithName:#"HelveticaNeue-Thin" size:16.0f];
will work.
However if you are targeting iOS 6.1 and below you'll need to embed the font
Updated answer to support swift
let font = UIFont(name: "HelveticaNeue-Thin", size: 16.0)!
UIFontDescriptor *helveticaNeueFamily =
[UIFontDescriptor fontDescriptorWithFontAttributes:
#{ UIFontDescriptorFamilyAttribute: #"Helvetica Neue" }];
NSArray *matches =
[helveticaNeueFamily matchingFontDescriptorsWithMandatoryKeys: nil];
The matchingFontDescriptorsWithMandatoryKeys: method as shown returns an array of font descriptors for all the Helvetica Neue fonts on the system, such as HelveticaNeue, HelveticaNeue-Medium, HelveticaNeue-Light, HelveticaNeue-Thin, and so on.
You can modify the fonts returned by preferredFontForTextStyle: by applying symbolic traits, such as bold, italic, expanded, and condensed. You can use font descriptors to modify particular traits, as shown in Listing 9-2.
referenced by apple
or
this font you can't apply directly.
so you can customize your font
How to use custom fonts in iPhone SDK?
This has worked for me. Write this code below your label declarations.
It sets all the UILabel under a function with same font.
[[UILabel appearance]setFont:[UIFont fontWithName:#"HelveticaNeue-Thin" size:32.0f]];
To set font to particular UILabel use this code :
[labelName setFont:[UIFont fontWithName:#"HelveticaNeue-Thin" size:15.0f]];
As I understand all standard controls use system font by default.
Also, API [UIFont systemFontOfSize: ] uses system font too.
Is there a way to redefine it for the whole application, instead of setting a font for table, labels and so on?
The answer is no, you cant change apple's systemFont, you need to set the font on your control yourself.
For best way to set a default font for whole iOS app, please check the below SO questions:
Set a default font for whole iOS app?
How to set a custom font for entire iOS app without specifying size
How do I set a custom font for the whole application?
Is there a simple way to set a default font for the whole app?
Define and export (by including a header in files or in precompiled header) a category of UIFont as following:
#implementation UIFont (Utils)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
+ (UIFont *)systemFontOfSize:(CGFloat)size
{
return [UIFont fontWithName:#"YOUR_TRUETYPE_FONT_NAME_HERE" size:size];
}
+ (UIFont *)lightSystemFontOfSize:(CGFloat)size
{
return [UIFont fontWithName:#"YOUR_TRUETYPE_FONT_NAME_HERE" size:size];
}
+ (UIFont *)boldSystemFontOfSize:(CGFloat)size
{
return [UIFont fontWithName:#"YOUR_TRUETYPE_FONT_NAME_HERE" size:size];
}
+ (UIFont *)preferredFontForTextStyle:(NSString *)style
{
if ([style isEqualToString:UIFontTextStyleBody])
return [UIFont systemFontOfSize:17];
if ([style isEqualToString:UIFontTextStyleHeadline])
return [UIFont boldSystemFontOfSize:17];
if ([style isEqualToString:UIFontTextStyleSubheadline])
return [UIFont systemFontOfSize:15];
if ([style isEqualToString:UIFontTextStyleFootnote])
return [UIFont systemFontOfSize:13];
if ([style isEqualToString:UIFontTextStyleCaption1])
return [UIFont systemFontOfSize:12];
if ([style isEqualToString:UIFontTextStyleCaption2])
return [UIFont systemFontOfSize:11];
return [UIFont systemFontOfSize:17];
}
#pragma clang diagnostic pop
#end
Light variant comes as a useful extra starting with iOS 7. Enjoy! ;)
I have recently started using avenir as the font for my button text in my storyboard. It looks normal when I run it on ios6 , however in ios5 and lower as it doesn't support avenir it just uses the system default which looks awful aswell as the text not all fiting in the button, like so
Can anyone tell me how I would select a different font and text size for ios5, or a different font and text size when it returns nil to avenir?
UIFont *font = [UIFont fontWithName:#"iOS 6 font" size:SIZE];
if (!font) {
font = [UIFont fontWithName:#"Legacy font" size:SIZE];
}
I want to add GillSans-Bold font to a UILabel.
I have set it in the xib file , and I'm also setting it up in my class as follows :
[label setFont:[UIFont fontWithName:#"GillSans-Bold" size:18]];
But , it doesn't seem to work for me.
Any suggestions ?
iPhone 4.3 doesn't have Gill Sans, but iPad has it since 3.2.1.
See this list comparing fonts for iPad 4.3 and iPhone 4.3. To be sure, this is how you get the list of fonts available on your device:
for (NSString *familyName in [UIFont familyNames]) {
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(#"%#", fontName);
}
}
If it says
GillSans
GillSans-Bold
GillSans-BoldItalic
GillSans-Italic
then [UIFont fontWithName:#"GillSans-Bold" size:18] should return a valid font.
For this to be working I had to add this font in my project directory , and added this font in the Info.Plist file
Does the font GillSans-Bold exist? Check if [UIFont fontWithName:#"GillSans-Bold" size:18] returns an UIFont, not null.
Swift
let label = UILabel()
label.font = UIFont(name: "Roboto-Regular", size: 16)
label.text = "Your text here"
P.S. Before that you must:
Add custom font in project
Add font names in Info.plist file
Add font files in Copy Bundle Resources
After that you can also use this fonts in storyboards