私のデバイス上に正常に表示されているHTMLファイルがありますが、デバイス上にCSSファイルがロードされません。ブラウザでHTMLを開くと、CSSが正常に動作しています。Swift 3でCSSファイルをHTMLで読み込むにはどうしたらいいですか?
これは私の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;
}
また、これはスウィフト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に新しいので、私はそれについてはあまり知らない。 –