我正在尝试将自定义css文件添加到uiwebview
以将一些元素放入display:none
,但经过大量的Google搜索后,我无法找到方法。我似乎应该通过javascript注入它,但我真的不知道如何。以前有人这么做过吗?
答案 0 :(得分:0)
您可以执行以下操作,当您加载html文件时,您可以在项目中添加CSS文件并在webview中加载html,请参阅: - link
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let localfilePath = NSBundle.mainBundle().URLForResource("test", withExtension: "html");
let myRequest = NSURLRequest(URL: localfilePath!);
webView.loadRequest(myRequest);
//or use as below
let myHTMLString:String! = "<h1>Hello Pizza!</h1>"
webView.loadHTMLString(myHTMLString, baseURL: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}