用swift 加载html文件

// 首先呢要把这个HTML文件加入到项目之中

 class WebViewController: UIViewController {     

override func viewDidLoad() {     

 super.viewDidLoad()        

//检查 BullsEye.html是否存在       

if let htmlFile = NSBundle.mainBundle().pathForResource("BullsEye", ofType: "html"){       

      let htmlData = NSData(contentsOfFile: htmlFile)          

  let baseURL = NSURL.fileURLWithPath(NSBundle.mainBundle().bundlePath)        

    web.loadData(htmlData, MIMEType: "text/html", textEncodingName: "UTF-8", baseURL: baseURL)     

  }

    }      //UIWebView    @IBOutlet weak var web: UIWebView! 

}

你可能感兴趣的:(用swift 加载html文件)