让iOS在CSS中选择系统字体Helvetica Neue或旧金山 [英] Let iOS pick the System Font Helvetica Neue or San Francisco in CSS
问题描述
是否可以在指向iOS的 CSS
中指定一个系统字体(显示在 UIWebView
),并获得与使用 Interface Builder 设计类似的结果:
font-family:Helvetica Neue
: < HTML>
< head>
< style type = \text / css \>
body {font-family:Helvetica Neue; font-size:14;}
< / style>
< / head>
< body>< / body>
< / html>
系统 p>
UIFont.systemFontOfSize(),UIFont.boldSystemFontOfSize(),UIFont.italicSystemFontOfSize()
系统+权重 $ b
> let mediumWeight = UIFont.systemFontOfSize(17,weight:UIFontWeightMedium)
UIFontWeightUltraLight,UIFontWeightThin,UIFontWeightLight ,UIFontWeightRegular,UIFontWeightMedium,UIFontWeightSemibold,UIFontWeightBold,UIFontWeightHeavy,UIFontWeightBlack
文字样式
正文,标注,标题1,标题2,脚注,标题,分目,标题1,标题2,标题3
在iOS和OS X上的
对font-familyCSS属性使用-apple-systemCSS值。
正如
►在 GitHub 以及有关 Swift Recipes 的其他详细信息。
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:
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
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>
► Find this solution on GitHub and additional details on Swift Recipes.
这篇关于让iOS在CSS中选择系统字体Helvetica Neue或旧金山的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!