请注意这个简单的 css/html,它显示在本地 UIWebView 中:
有模拟器显示它...
请注意,有两个 @font-face 定义。
But ... 只有第二个有效。如果你交换它们,只有第二个有效。
所以在这里 ...
@font-face {
font-family:'aaa';
src: local('SourceSansPro-Regular'),
url('SourceSansPro-Regular.ttf') format('truetype');
}
@font-face {
font-family:'bbb';
src: local('SourceSansPro-BoldIt'),
url('SourceSansPro-BoldItalic.ttf') format('truetype');
}
只有“bbb”有效,另一项似乎被“取消”了。那么这里..
@font-face {
font-family:'bbb';
src: local('SourceSansPro-BoldIt'),
url('SourceSansPro-BoldItalic.ttf') format('truetype');
}
@font-face {
font-family:'aaa';
src: local('SourceSansPro-Regular'),
url('SourceSansPro-Regular.ttf') format('truetype');
}
只有“aaa”有效,另一项似乎被“取消”了。
以下是如何在 Swift 中做到这一点,
// load a simple UIWebView (say, an "about" or "legal" screen)
// base is in template.html
import UIKit
import WebKit
class MinorWebView:UIViewController
{
@IBOutlet var wv:UIWebView!
@IBInspectable var filename:String = "?"
// for example, "about" for "about.html"
...
func makeHtml()
{
print("making html for ... " ,filename)
let ourSize = grid.yourSizeDecisionMechanism
let sizeString = String(format:"%.0f", ourSize)
let p1 = NSBundle.mainBundle().pathForResource("template", ofType: "html")
var html:String = try! NSString(contentsOfFile:p1!, encoding:NSUTF8StringEncoding) as String
let p2 = NSBundle.mainBundle().pathForResource(filename, ofType: "html")
let content:String = try! NSString(contentsOfFile:p2!, encoding:NSUTF8StringEncoding) as String
html = html.stringByReplacingOccurrencesOfString("STUFF", withString:content)
html = html.stringByReplacingOccurrencesOfString("SIZEPOINTS", withString:sizeString)
print("Made html like this ---\n" ,html ,"\n------")
wv.loadHTMLString(html as String, baseURL:nil)
}
}
只需将“template.html”和“about.html”拖到项目中(就像处理图像一样);确保他们有目标会员资格。