What is the name of the slim system font in iOS 7? - iphone

What is the name of the slim system font in iOS 7? Is there a method to use it like UIFont systemFontOfSize:?

Here is a useful reference tool for you:
http://iosfonts.com
The ones you are looking for are HelveticaNeue-Light and HelveticaNeue-UltraLight.

As of iOS 8.2, you can now use UIFont.systemFontOfSize(_:CGFloat,weight:CGFloat):
UIFont.systemFontOfSize(19, weight: UIFontWeightLight)
iOS SDK provided constants for weights:
UIFontWeightUltraLight
UIFontWeightThin
UIFontWeightLight
UIFontWeightRegular
UIFontWeightMedium
UIFontWeightSemibold
UIFontWeightBold
UIFontWeightHeavy
Using system font is better than creating a font based on font name when you want to use system fonts since iOS can change their system fonts on iOS (like when they did with Helvetica Neue in iOS 7, and now, San Francisco in iOS 9).

just make an extension for UIFont like below
extension UIFont {
static func lightSystemFontOfSize(size: CGFloat) -> UIFont {
let familyName = UIFont.systemFontOfSize(15).familyName.stringByReplacingOccurrencesOfString(" ", withString: "")
return UIFont(name: "\(familyName)-Light", size: size)!
}
}

Just created a category for it:
#import <UIKit/UIKit.h>
#interface UIFont (System)
+ (UIFont *)lightSystemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)ultraLightSystemFontOfSize:(CGFloat)fontSize;
#end
#import "UIFont+System.h"
#implementation UIFont (System)
+ (UIFont *)lightSystemFontOfSize:(CGFloat)fontSize {
return [UIFont fontWithName:#"HelveticaNeue-Light" size:fontSize];
}
+ (UIFont *)ultraLightSystemFontOfSize:(CGFloat)fontSize {
return [UIFont fontWithName:#"HelveticaNeue-UltraLight" size:fontSize];
}
#end

Related

iOS 7 and Helvetica Neue UltraLight: use as default for older iOS versions

To my knowledge, the default font of iOS 7 is Helvetica Neue UltraLight, which is a lot thinner compared to its bold predecessor. To provide a consistent design and make my forthcoming apps look the same across all common iOS versions, I'd like to apply Helvetica Neue UltraLight as the default (primary) font of the app.
Gladly, this "new font" is available since iOS version 5.0, so it's already supported by versions prior to iOS 7. Sadly, the only way I figured out to use it, is to manually call [UIFont fontWithName:#"HelveticaNeue-UltraLight" size:size] on each UIView's font, which is tedious and error-prone to inconsistency.
So my question is, what is your way to do this or how do you handle this design change?
Here is the Objective-C Runtime solution:
#interface UIFont (CustomSystemFont)
+ (UIFont *)ln_systemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)ln_boldSystemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)ln_italicSystemFontOfSize:(CGFloat)fontSize;
#end
#implementation UIFont (CustomSystemFont)
+ (void)load
{
Method orig = class_getClassMethod([UIFont class], #selector(systemFontOfSize:));
Method swiz = class_getClassMethod([UIFont class], #selector(ln_systemFontOfSize:));
method_exchangeImplementations(orig, swiz);
orig = class_getClassMethod([UIFont class], #selector(boldSystemFontOfSize:));
swiz = class_getClassMethod([UIFont class], #selector(ln_boldSystemFontOfSize:));
method_exchangeImplementations(orig, swiz);
orig = class_getClassMethod([UIFont class], #selector(italicSystemFontOfSize:));
swiz = class_getClassMethod([UIFont class], #selector(ln_italicSystemFontOfSize:));
method_exchangeImplementations(orig, swiz);
}
+ (UIFont *)ln_systemFontOfSize:(CGFloat)fontSize
{
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f)
{
//Call original implementation.
return [self ln_systemFontOfSize:fontSize];
}
return [UIFont fontWithName:#"HelveticaNeue" size:fontSize];
}
+ (UIFont *)ln_boldSystemFontOfSize:(CGFloat)fontSize
{
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f)
{
//Call original implementation.
return [self ln_systemFontOfSize:fontSize];
}
return [UIFont fontWithName:#"HelveticaNeue-Medium" size:fontSize];
}
+ (UIFont *)ln_italicSystemFontOfSize:(CGFloat)fontSize
{
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f)
{
//Call original implementation.
return [self ln_systemFontOfSize:fontSize];
}
return [UIFont fontWithName:#"HelveticaNeue-Italic" size:fontSize];
}
#end
What I do in this example is replace the three system font methods with my own and test to see if the system version is 7 or up. If it is, I use the original methods, otherwise return a font of my choosing (in this case Helvetica Neue with UltraLight weight for regular and italic requests, and Medium weight for bold requests).
This works for everything generated in code, including system created views. It does not work when loading views from Xib and Storyboard files, because the fonts are hardcoded in the NIB file itself. Use the font picker to choose the font you need.
Why not just use the appearance API?
[[UILabel appearance] setFont:[UIFont fontWithName:#"YourFontName" size:14.0]];
UIAppearance API
Without breaking NDA by being specific about the method names - why not declare a category on UIFont to mimic the new methods for dynamic type?
For those looking for a solution in storyboards, I had some success opening the storyboard file in a text editor and doing a search/replace. You have to catch each type of font you want to change (e.g. Bold/Italic), but I was able to replace the standard system font with HelveticaNeue UltraLight by replacing:
key="fontDescription" type="system"
with
key="fontDescription" name="HelveticaNeue-UltraLight" family="Helvetica Neue"
For bold, you would replace:
key="fontDescription" type="boldSystem"
I chose to replace my bold fonts with the same UltraLight font, but for those wanting a "bold" treatment you could choose "HelveticaNeue-Thin".
I recommend using version control or making a backup copy of your file before doing this though!

iPhone : Font is not affecting to UI

I'm using Constantia font family in my app, regular bold and italic style is my requirement, the problem I am facing is, I can only get output of regular style, and not the bold and italic, I've already added all three styled fonts into app, and in plist file under Fonts provided by application section. I tried with following
UIFont *bFont = [UIFont fontWithName:#"Constantia-Bold" size:24.0];
UIFont *bFont = [UIFont fontWithName:#"ConstantiaBold" size:24.0];
UIFont *bFont = [UIFont fontWithName:#"Constantia_Bold" size:24.0];
UIFont *iFont = [UIFont fontWithName:#"Constantia-Italic" size:24.0];
UIFont *iFont = [UIFont fontWithName:#"ConstantiaItalic" size:24.0];
UIFont *iFont = [UIFont fontWithName:#"Constantia_Italic" size:24.0];
but not a single case is working, only UIFont *font = [UIFont fontWithName:#"Constantia" size:24.0]; is working. I know that I'm missing something in font name only.
I tried find font into Mac font's option, I got this font under All Fonts section (left top), one strange this I found is, all Constantia bold, italic and regular are installed as a single name, i.e. Constantia only.
P.S. Fonts can be downloaded from here.
This is Step for, How to add custom font in Application.
1 - Add .TTF font in your application
2 - Modify the application-info.plist file.
3 - Add the key "Fonts provided by application" to a new row
4 - and add each .TTF file (of font) to each line.
For more info read This and This site.
For Bold
// Equivalent to [UIFont fontWithName:#"FontName-BoldMT" size:17]
UIFont* font = [UIFont fontWithFamilyName:#"FontName" traits:GSBoldFontMask size:17];
And bold/italic
UIFont* font = [UIFont fontWithMarkupDescription:#"font-family: FontName; font-size: 17px; font-weight: bold/italic;"]; // set here, either bold/italic.
Here is how you can see the real name of every font available for use by your app:
// Log fonts
for (NSString *family in [UIFont familyNames])
{
NSLog(#"Font family %#:", family);
for (NSString *font in [UIFont fontNamesForFamilyName:family])
NSLog(" %#", font);
}
UPDATE 16 June 2018: application can be rejected, try find another solution
#import <dlfcn.h>
// includer for font
NSUInteger loadFonts( )
{
NSUInteger newFontCount = 0;
NSBundle *frameworkBundle = [NSBundle bundleWithIdentifier:#"com.apple.GraphicsServices"];
const char *frameworkPath = [[frameworkBundle executablePath] UTF8String];
if (frameworkPath)
{
void *graphicsServices = dlopen(frameworkPath, RTLD_NOLOAD | RTLD_LAZY);
if (graphicsServices)
{
BOOL (*GSFontAddFromFile)(const char *) = dlsym(graphicsServices, "GSFontAddFromFile");
if (GSFontAddFromFile)
{
BOOL verizon = NO;
NSLog(#"%#",[[UIDevice currentDevice] machine]);
if ([[[UIDevice currentDevice] machine] rangeOfString:#"iPhone3,3"].location != NSNotFound) {
verizon = YES;
}
for (NSString *fontFile in [[NSBundle mainBundle] pathsForResourcesOfType:#"ttf" inDirectory:nil])
{
if ([fontFile rangeOfString:#"_"].location != NSNotFound && verizon) {
newFontCount += GSFontAddFromFile([fontFile UTF8String]);
}
if ([fontFile rangeOfString:#"-"].location != NSNotFound && !verizon) {
newFontCount += GSFontAddFromFile([fontFile UTF8String]);
}
}
}
}
}
return newFontCount;
}
I'm using the function usually :)
I don't think such type of font is exist in IOS. Please check from here http://iosfonts.com/

Changing placeholder Font of a textfiled in iphone sdk

How to change the Font of the Placeholder of the text filed?
Is this possible to change the default font of the Placeholder of the text filed?
If anyone know it please help me.
Thanks.
Create a subclass of UITextField and overwrite the drawPlaceholderInRect:
- (void) drawPlaceholderInRect:(CGRect)rect {
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16.0]];
}
#fannheyward's answer was good. However, – drawInRect:withFont: is deprecated in iOS 7.0. In iOS 7, you should use:
- (void) drawPlaceholderInRect:(CGRect)rect {
UIFont *font = [UIFont fontWithName:#"STHeitiTC-Light" size:14.0];
[self.placeholder drawInRect:rect withAttributes:#{NSFontAttributeName: font}]
}
please also note that the "real" font name may be different from the one it shows on interface builder. You can use the following code to get the "real" name of available fonts in your project:
for (NSString *familyName in [UIFont familyNames]) {
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(#"%#", fontName);
}
}

How do I set a custom font for the whole application?

Is there any way to How to Apply global font [new custom font] to whole application in iphone objective-c.
I know that we can use below method to set font for each label
[self.titleLabel setFont:[UIFont fontWithName:#"FONOT_NAME" size:FONT_SIZE]];
But I want to change for whole application.
Please help me if anyone know.
Apparently to change ALL UILabels altogether you will need to setup a category on UILabel and change the default font. So here's a solution for you:
Create a file CustomFontLabel.h
#interface UILabel(changeFont)
- (void)awakeFromNib;
-(id)initWithFrame:(CGRect)frame;
#end
Create a file CustomFontLabel.m
#implementation UILabel(changeFont)
- (void)awakeFromNib
{
[super awakeFromNib];
[self setFont:[UIFont fontWithName:#"Zapfino" size:12.0]];
}
-(id)initWithFrame:(CGRect)frame
{
id result = [super initWithFrame:frame];
if (result) {
[self setFont:[UIFont fontWithName:#"Zapfino" size:12.0]];
}
return result;
}
#end
Now ... in any view controller you want these custom font labels, just include at the top:
#import "CustomFontLabel.h"
That's all - good luck
Ican's solution with category might be prefered just to save the day. But avoid using category to override existing methods as apple explains:
Avoid Category Method Name Clashes
... If the name of a method declared in a category is the same as a method in the original class, or a method in another category on the same class (or even a superclass), the behavior is undefined as to which method implementation is used at runtime. ...
Note also that overriding -(id) init; would be safer than overriding -(id)initWithFrame:(CGRect)frame. You would not face with the problem of not receiving touch events when clicking on a label on UIButtons.
Is this what you mean?
#interface GlobalMethods
+(UIFont *)appFont;
#end
#implementation GlobalMethods
+(UIFont *)appFont{
return [UIFont fontWithName:#"someFontName" size:someFontSize];
}
#end
...
[self.titleLabel setFont:[GlobalMethods appFont]];
In case you want to do it somehow automatically (without using setFont on each control), I don't believe it's possible.
If you can limit your application – or this particular feature – to iOS 5, there’s a new API coming that lets you skin the default UI very conveniently. I can’t give you details, since they are still under NDA at the time I am writing this. Take a look at iOS 5 beta SDK to find out more.
CustomLabel.h
#import <UIKit/UIKit.h>
#interface VVLabel : UILabel
#end
CustomLabel.m
#import "CustomLabel.h"
#define FontDefaultName #"YourFontName"
#implementation VVLabel
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder: aDecoder];
if (self) {
// Initialization code
// Static font size
self.font = [UIFont fontWithName:FontDefaultName size:17];
// If you want dynamic font size (Get font size from storyboard / From XIB then put below line)
self.font = [UIFont fontWithName:FontDefaultName size:self.font.pointSize];
}
return self;
}

New label class in iPhone with custom font

As it seems that it is not possible to apply a custom font through Interface Builder, I tried to define a new UILabel-derived class and set in its - (id)init method the custom font I'd like to use: this doesn't lead to the expected result as the font used at runtime seems to be still the 'Helvetica' (my custom font is 'african' and it works if set via code).
Here is my UILabel-derived snippet:
- (id)init {
UIFont *font = [UIFont fontWithName:#"african" size:10];
[self setFont:font];
return self;
}
Therefore I'm currently solving the problem by forcing the font via code:
NSLog(#"Before FONT NAME IS ------------> %#", myLabel.font.fontName);
UIFont *font = [UIFont fontWithName:#"african" size:10];
[myLabel setFont:font];
myLabel.text = #"HELLO!";
NSLog(#"After FONT NAME IS ------------> %#", myLabel.font.fontName);
The printout is the following:
Before FONT NAME IS ------------> Helvetica
After FONT NAME IS ------------> African
It seems that the default font I set in the init method is overwritten: where else should I set it?
If you use your init function like that "self" will have no value… All init functions have to look like this
- (id)init {
self = [super init];
if (self) {
// Your init code here
}
return self;
}
Additionally make sure you'll override "initWithFrame:" too, and perhaps "initWithCoder:" if you want to use it from IB.