What is the name of the default system font on the iPhone?
I would like to retrieve this for customizing a UIView.
To the delight of font purists
everywhere, the iPhone system
interface uses Helvetica or a variant
thereof.
The original iPhone, iPhone 3G and
iPhone 3GS system interface uses
Helvetica. As first noted by the
always excellent DaringFireball, the
iPhone 4 uses a subtly revised font
called "Helvetica Neue."
DaringFireball also notes that this
change is related to the iPhone 4
display rather than the iOS 4
operating system and older iPhone
models running iOS 4 still use
Helvetica as the system font.
iPod models released prior to the
iPhone use either Chicago, Espy Sans,
or Myriad and use Helvetica after the
release of the iPhone.
From http://www.everyipod.com/iphone-faq/iphone-who-designed-iphone-font-used-iphone-ringtones.html
For iOS9 it has changed to San Francisco. See http://developer.apple.com/fonts for more info.
If you're doing programatic customisation, don't hard code the system font. Use UIFont systemFontOfSize:, UIFont boldSystemFontOfSize: and UIFont italicSystemFontOfSize (Apple documentation).
This has become especially relevant since iOS 7, which changed the system font to Helvetica Neue.
This has become super especially relevant since iOS 9, which changed the system font again to San Francisco.
afaik iPhone uses "Helvetica" by default
< iOS 10
Swift
Specific font
Setting a specific font in Swift is done like this:
let myFont = UIFont(name: "Helvetica", size: 17)
If you don't know the name, you can get a list of the available font names like this:
print(UIFont.familyNames())
Or an even more detailed list like this:
for familyName in UIFont.familyNames() {
print(UIFont.fontNamesForFamilyName(familyName))
}
But the system font changes from version to version of iOS. So it would be better to get the system font dynamically.
System font
let myFont = UIFont.systemFontOfSize(17)
But we have the size hard-coded in. What if the user's eyes are bad and they want to make the font larger? Of course, you could make a setting in your app for the user to change the font size, but this would be annoying if the user had to do this separately for every single app on their phone. It would be easier to just make one change in the general settings...
Dynamic font
let myFont = UIFont.preferredFont(forTextStyle: .body)
Ah, now we have the system font at the user's chosen size for the Text Style we are working with. This is the recommended way of setting the font. See Supporting Dynamic Type for more info on this.
Related
Visual List of iOS Fonts
How do I make an attributed string using Swift?
You can always use
UIFont *systemFont = [UIFont systemFontOfSize:12];
NSLog(#"what is it? %# %#", systemFont.familyName, systemFont.fontName);
The answer is:
Up to iOS 6
Helvetica Helvetica
iOS 7
.Helvetica Neue Interface .HelveticaNeueInterface-M3
but you can just use Helvetica Neue
I'm not sure there is an api to get the default system font name. So I just get the name like this :
//get system default font
UILabel *label = [[UILabel alloc] init];
fontname = label.font.fontName;
[label release];
Looks stupid but it works.
Here is some update for supporting iOS 7. It has Dynamic Font Size now.
For any and all apps that support “Dynamic Type,” users can select a
font size in iOS 7 that works system wide, simply by visiting the
"General" section under "Settings" and selecting "Font Size."
UIFont *dynamicFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
And constants list, detailed explanation is here
NSString *const UIFontTextStyleHeadline;
NSString *const UIFontTextStyleSubheadline;
NSString *const UIFontTextStyleBody;
NSString *const UIFontTextStyleFootnote;
NSString *const UIFontTextStyleCaption1;
NSString *const UIFontTextStyleCaption2;
Category UIFontSystemFonts for UIFont (UIInterface.h) provides several convenient predefined sizes.
#interface UIFont (UIFontSystemFonts)
+ (CGFloat)labelFontSize;
+ (CGFloat)buttonFontSize;
+ (CGFloat)smallSystemFontSize;
+ (CGFloat)systemFontSize;
#end
I use it for chat messages (labels) and it work well when I need to get size of text blocks.
[UIFont systemFontOfSize:[UIFont labelFontSize]];
Happy coding!
UIFont *systemFont = [UIFont systemFontOfSize:[UIFont systemFontSize]];
This will give you the system font with the default system font size applied for the label texts by default.
Swift
You should always use the system defaults and not hard coding the font name because the default font could be changed by Apple at any time.
There are a couple of system default fonts(normal, bold, italic) with different sizes(label, button, others):
let font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
let font2 = UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)
let font3 = UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)
beaware that the default font size depends on the target view (label, button, others)
Examples:
let labelFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
let buttonFont = UIFont.systemFont(ofSize: UIFont.buttonFontSize)
let textFieldFont = UIFont.systemFont(ofSize: UIFont.systemFontSize)
download required .ttf file
add the .ttf file under copy bundle resource, double check whether
the ttf file is added under resource
In info.pllist add the ttf file name as it is.
now open the font book add the .ttf file in the font book, select
information icon there you find the postscript name.
now give the postscript name in the place of font name
The default font for iOS is San Francisco . You can refer the link for further details
Related
I got a file(please find attached file) which contain font, this font supposed to display icons according to code number.
but i didn't succeed to display any icon with this font. here is my code:
iconTest = UILabel();
iconTest.frame = CGRectMake(0, 0, 100, 100);
onTest.center = self.view.center;
iconTest.font = UIFont(name: "icomoon", size:16.0);
iconTest.text = "e906";
what's the correct way to display icons using font !
download font svg file
You have to set text property like:
iconTest.text = "\u{e906}";
Do not forget to register your custom font in your app.
Follow these steps:
Install fonts by double clicking on them.
Drag and drop fonts in Xcode and make sure they are added to target. (check copy items if needed)
In info.plist, set key Fonts provided by application and add font name for item(under key)
Set font type custom in storyboard for your controls or programatically assign font to UILabel
Code:
//In swift 3
let font = UIFont(name: "iconmoon", size: 15)
btnSignout.setTitle("\u{e913}", for: UIControlState.normal) // set font icon on UIButton
btnSignout.titleLabel!.font = font
// In objectiveC
_lbl.text = [NSString stringWithUTF8String:"\ue92e"]; // set font icon on UILabel
_lbl.font = [UIFont fontWithName:#"iconmoon" size:16];
Note: \u prefix is mandatory, Example for unicode e626, the label text should be \ue626 or \u{e626}
I use icon font in some of my projects. I have create a project to use icon font easily. The README of this project is written in Chinese. But the demo project will show everything clearly. https://github.com/JohnWong/IconFont
Icon font is always used in UILabel by setting text. But I think creating a UIImage from font is more flexible. This is why I create this project.
Method of register font by setting project is in answer provided by martin. Here is a way to register font by code: https://github.com/JohnWong/IconFont/blob/master/IconFont/TBCityIconFont.m#L16
Icomoon.swift: Use your Icomoon fonts with Swift - auto-generates type safe enums for each icon.
Despite it's not IcoMoon, this library is worth noting:
https://github.com/0x73/SDevIconFonts
It integrates FontAwesome, Ionicons, Octicons and Iconic as Icon Fonts.
Assign them with code as easy as:
label.font = UIFont.iconFontOfSize(.FontAwesome, fontSize: 50.0)
label.text = String.fontAwesomeIconWithName(.Twitter)
As noted before, you have to register the font files in your app's Info.plist.
Anyway, regarding IcoMoon: I would use the above library as a starting point. Should be fairly easy (*) to add IcoMoon in a fork (or better as a pull request).
(*) technically spoken, adding a list of convenience shortcuts like .Twitter is quite an expensive task when I have a look at https://github.com/0x73/SDevIconFonts/blob/master/SDevIconFonts/Classes/FontAwesome.swift.
I am trying to use the very same font in a UIWebView on iOS that the iOS system uses currently.
This means I want to use the very same font I'd get from:
UIFontDescriptor *fd;
fd = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
UIFont *font = [UIFont fontWithDescriptor:fd size:0];
There are lots of answers on SO (iPhone Development - Setting UIWebView font, Using custom font in a UIWebView, How to change UIWebView default font, How to set custom font in UIWebView?) that explain how to embed a UIFont's familyName or fontName into an html's style attributes, by doing this:
NSString *fontStyle, *htmlString = #"test";
fontStyle = [NSString stringWithFormat:#"font-family:%#;font-size:%d", font.familyName, (int)font.pointSize];
htmlString = NSString stringWithFormat:#"<span style=\"%#\">%#</span>", fontStyle, htmlString];
But this doesn't seem to work on iOS 7 and 8 any more where these system font names are now like:
font.fontName: .HelveticaNeueInterface-Regular
font.familyName: .Helvetica Neue Interface
When using these names in an UIWebView with the "font-family" attribute, the text gets rendered in the default font (which is with serifs and certainly not the new iOS system font). Removing the leading period doesn't help, either.
So, how do I now translate the system's font into a name that gets correctly interpreted by the Web Kit?
Please understand that I am seeking for a generic solution and do not simply seek the iOS 7/8 name I can insert manually into the html style attribute.
I just ran into this blog article which may offer the solution though I have not verified it yet:
If you're trying to reference the system font in web views just prepend -apple-system to your font-family list and it'll use SF in iOS 9 and Helvetica in older versions.
Which means that the font line of above code needs to be change to:
fontStyle = [NSString stringWithFormat:#"font-family:-apple-system,Helvetica Neue;font-size:%d", (int)font.pointSize];
That should take care of selecting the system font from iOS 7 onward.
what about this article: http://furbo.org/2015/07/09/i-left-my-system-fonts-in-san-francisco/ from Craig Hockenberry?
Have you tried Helvetica or San Francisco with attaching font files?
I want to use DTCoreText in my app to convert HTML to NSAttributedString, but I can't figure out how to use the system font (as of iOS 8: Helvetica Neue) as the base font. By default DTCoreText seems to create the NSAttributedString with the Times New Roman font.
I'd really prefer not to hardcode it. If Apple updates their font again (they previously updated it from Helvetica to Helvetica Neue) I don't want to replace all instances of it, or have a bunch of conditionals depending on the OS version running the code.
I tried:
NSDictionary *options = #{
DTUseiOS6Attributes: #(YES),
DTDefaultFontFamily: [UIFont systemFontOfSize:[UIFont systemFontSize]].fontName
};
But it still renders as Times New Roman.
How do I make it use the system font? I just want it to look normal.
Looks like DCCoreText is expecting to receive font family name, and you're providing font name which is different. Try to replace your code with
[UIFont systemFontOfSize:[UIFont systemFontSize]].familyName
I have embedded font in ios, like the normal version italics and all by following methodes.
1.Added font to project folder.
2.Added font names "MuseoSans_100.otf" inside "Fonts provided by application" in info.plist.
3. created UIFont in viewdidload method
UIFont *newfont = [UIFont fontWithName:#"MuseoSans_100" size:13.0];
[labelname setFont:newfont];
but when i run this in simulator, i can see the font and size are not changing.
Please help.
You can use the fontNamesForFamilyName: method to retrieve the specific font names for a given font family.
Check the font family
NSLog(#"%#",[UIFont fontNamesForFamilyName:#"MuseoSans_100"]);
This question already has answers here:
Can I embed a custom font in an iPhone application?
(32 answers)
How to include and use new fonts in iPhone SDK?
(9 answers)
Closed 8 years ago.
I am import the font in my app folder.
Then i added font in info.plist file.
Like..... Fonts provided by application--->add two font.
Then set the font to title.After create the UILabel to set the font. Like this
self.title = #"Home";
CGRect frame = CGRectMake(0, 0,100, 44);
label = [[UILabel alloc] initWithFrame:frame];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:#"Benguiat Gothic" size:9];
label.textAlignment = UITextAlignmentCenter;
self.navigationItem.titleView = label;
label.text =self.title;
This code written in viewdidload method.
But the font is not changed.its appear only default font for that label.
1 Add your custom font into your project , i.e. Dragged the font file(CALIBRIZ_0.TTF) into XCode project.
2 Edit Info.plist: Add a new entry with the key "Fonts provided by application".
3 For each of your files, add the file name to this array
4.Opened the font in font book(double click on your font in finder) to see what the real filename is and I see this:
Now set font to your label
yourLabel.font = [UIFont fontWithName:#"Calibri" size:15];
First download your relevant font
Add your custom font into your project , i.e. Dragged the font file(Berlin Sans FB.TTF) into XCode project.
Add a new entry with the key "Fonts provided by application".
Now use this font in your textview
txtview.font = [UIFont fontWithName:#"Berlin Sans FB" size:15];
i used Berlin Sans FB you use your teleugu font
for more detail check this link
Using a custom font in iOS requires a few steps:
Have access to the TTF or OTF file for the desired font.
Drag the TTF or OTF font file into your Xcode project.
Located the application's Plist file and add a new row with the key "Fonts provided by the application.
Make sure that the associated value in the Plist perfectly matches the naming of the dragged in font file.
In your code, you can now assign the custom font to be used with your label, textfield or any other control that has the font property.
[myLabel setFont:[UIFont fontWithName:#"Benguiat Gothic" size:12.0f]];
Or, if you prefer dot notation syntax
myLabel.font = [UIFont fontWithName:#"Benguiat Gothic" size: 12.0f];
There's a few things to take into consideration. The actual naming of the Font File may not always be what you have to pass in as a string literal. Some custom fonts may have different weights associated with it (Light, Regular, Medium, Bold, Italic Bold etc). If the font isn't displaying as you would expect and all steps above have been explicitly followed then it could be down to the string you're using in your code.
You can get the list of font family names in debug by logging out as so:
NSLog (#"Font families: %#", [UIFont familyNames]);
That should give you a decent indication of what to actually use in your code when defining the custom font for use with the label.