让iOS在CSS中选择系统字体Helvetica Neue或旧金山

是否可以在针对iOS的CSS指定系统字体(在UIWebView显示),并获得与使用Interface Builder进行设计时类似的结果:

IB字体菜单

CSS设置SystemSystem + WeightText Styles而不是font-family:Helvetica Neue

    body{font-family:Helvetica Neue; font-size:14;}     

系统

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

系统+重量

如在let mediumWeight = UIFont.systemFontOfSize(17, weight: UIFontWeightMedium)

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

文字样式

 Body, Callout, Caption 1, Caption 2, Footnote, Headline, Subhead, Title 1, Title 2, Title 3 

在iOS和OS X上使用“font-family”CSS属性的“-apple-system”CSS值。

正如webkit.org上所述 ,目前在w3c中有关于标准化该值的讨论,因此作者可以简单地指定系统


系统字体

iOS 9和Safari OS X 10.11上的-apple-system

使用font-family: CSS属性:

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

在上下文中(当未定义-apple-system时,回-apple-system HelveticaNeue

       

重量和风格

使用font-weight: CSS属性:

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

使用font-style: CSS属性:

 normal, italic 

动态字体

iOS 8.4上的-apple-system-xxx

使用font: CSS属性(代表整个样式,包括大小和重量):

 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 

在上下文中:

       

在此处输入图像描述


►在GitHub上找到此解决方案以及有关Swift Recipes的其他详细信息。

为了进一步扩展@SwiftArchitect的正确答案,我使用Safari上的Mac在iOS设备(Safari中的iPhone 7)上调试了一个不可见的字体。 我的font-family是:

 h1, h2, h3, h4, h5 {font-family: "blisslight", blisslight, "blissregular", blissregular, Arial, sans-serif;} 

iOS忽略了所有后备字体,包括Arial,所以我最终使用它来使其工作:

 h1, h2, h3, h4, h5 {font-family: -apple-system, "blisslight", blisslight, "blissregular", blissregular, Arial, Helvetica, sans-serif;} 

尽管在Web Inspector中添加了新的CSS,但在上传新的CSS之前,Safari并没有将-apple-system渲染为可通过的代码。