【发布时间】:2017-07-07 10:15:55
【问题描述】:
我有一个 HTML 文件在我的设备上可以正常显示,但它没有在我的设备上加载其中的 CSS 文件。当我在浏览器上打开 HTML 时,我的 CSS 工作正常。
这是我的 HTML 代码:
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<h1>Prateek Bhatt</h1>
<br>
<p>is the greatest</p>
</body>
这是我的名为 stylesheet.css 的 CSS 文件:
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
这也是 Swift 3 的代码:
class ViewController: UIViewController {
@IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let htmlFile = Bundle.main.path(forResource: "index", ofType: "html")
let html = try? String(contentsOfFile: htmlFile!, encoding: String.Encoding.utf8)
webView.loadHTMLString(html!, baseURL: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
【问题讨论】:
-
我也是ios新手,所以不太了解。