Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Let iOS pick the System Font Helvetica Neue or San Francisco in CSS

Is it possible to specify a system font in a CSS targeted to iOS (to be displayed in a UIWebView), and get similar results as when designing with Interface Builder:

IB Font Menu

Can a CSS set System, System+Weight or Text Styles instead of font-family:Helvetica Neue:

<html> <head> <style type=\"text/css\">     body{font-family:Helvetica Neue; font-size:14;} </style> </head> <body></body> </html> 

System

UIFont.systemFontOfSize(), UIFont.boldSystemFontOfSize(), UIFont.italicSystemFontOfSize() 

System+Weight

As in let mediumWeight = UIFont.systemFontOfSize(17, weight: UIFontWeightMedium)

UIFontWeightUltraLight, UIFontWeightThin, UIFontWeightLight, UIFontWeightRegular, UIFontWeightMedium, UIFontWeightSemibold, UIFontWeightBold, UIFontWeightHeavy, UIFontWeightBlack 

Text Styles

Body, Callout, Caption 1, Caption 2, Footnote, Headline, Subhead, Title 1, Title 2, Title 3 
like image 790
SwiftArchitect Avatar asked Sep 05 '15 02:09

SwiftArchitect


People also ask

How do I use Helvetica Neue font in CSS?

To use this font on all devices, use a @font-face declaration in your CSS to link to it on your domain if you wish to use it. Just mind the copyright if you do. Make sure the licence you pay for includes web embedding.

Is Helvetica Neue an Apple font?

One of the most popular fonts in the world, Helvetica Neue (pronounced: noy-uh), is also a huge troublemaker. It was created in Switzerland in the 50s and adopted by Apple's design gurus back in 2013 for the iPhone. Apple's blessing only increased its popularity.


1 Answers

on iOS and OS X by using the “-apple-system” CSS value for the “font-family” CSS Property.

As noted on webkit.org, there are currently discussions in the w3c regarding standardizing this value so authors could simply specify system.


System Font

-apple-system on iOS 9 & Safari OS X 10.11

Using font-family: CSS Property:

font-family: -apple-system; font-family: '-apple-system','HelveticaNeue'; // iOS 8 compatible, credit: @MarcoBoschi 

In context (fallback to HelveticaNeue when -apple-system is undefined):

<html> <head> <style type=\"text/css\">     body{font-family: '-apple-system','HelveticaNeue'; font-size:17;} </style> </head> <body></body> </html> 

Weight & Style

Using font-weight: CSS Property:

normal, bold, bolder, lighter 100, 200, 300, 400, 500, 600, 700, 800, 900 

Using font-style: CSS Property:

normal, italic 

Dynamic Font

-apple-system-xxx on iOS 8.4.

Using font: CSS Property (represent an entire style, including size and weight):

font: -apple-system-body font: -apple-system-headline font: -apple-system-subheadline font: -apple-system-caption1 font: -apple-system-caption2 font: -apple-system-footnote font: -apple-system-short-body font: -apple-system-short-headline font: -apple-system-short-subheadline font: -apple-system-short-caption1 font: -apple-system-short-footnote font: -apple-system-tall-body 

In context:

<html> <head> <style type=\"text/css\">     body{font: -apple-system-body;} </style> </head> <body></body> </html> 

enter image description here


► Find this solution on GitHub and additional details on Swift Recipes.

like image 113
SwiftArchitect Avatar answered Oct 08 '22 05:10

SwiftArchitect