Hi to load a swift file in webView in ios :-
1- Add a WebView in your viewController
2- Create an IBOutlet for this.
3- set the delegate fro webView.
4- if you want to load the pdf from server or from an url use the function loadFromUrl()
5- if you want to load the pdf from you project or local use the function loadFromLocal() . to load from local you you have to add a file as name myPdfFile in your project.
func loadFromUrl(){
let url = NSURL(string:"https://www.yourpdfFileUrl.pdf")
myWebView?.loadRequest(NSURLRequest(URL: url!))
}
func loadFromLocal()
{
let pdfPath = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("myPdfFile", ofType: "pdf")!)
myWebView?.loadRequest(NSURLRequest(URL: pdfPath))
}
0 Comment(s)