[iOS] เปิดอ่าน PDF ด้วย Swift
Swift สามารถเขียนให้เปิด PDF โดยเลือกใช้ component WebView วาดลงใน storyboard และจัดการ layout ให้เรียบร้อย ตามรูปแบบการแสดงผลที่ต้องการ (จากตัวอย่างลองวาดเต็มจอ)
เขียนโปรแกรมเรียก *.pdf มาแสดงบน WebView
ซึ่งสามารถแสดงผลดังรูป
เขียนโปรแกรมเรียก *.pdf มาแสดงบน WebView
// Get the document's file path.
let path = NSBundle.mainBundle().pathForResource("sample.pdf", ofType: nil)
// Create an NSURL object based on the file path.
let url = NSURL.fileURLWithPath(path!)
// Create an NSURLRequest object.
let request = NSURLRequest(URL: url)
// Load the web viewer using the request object.
webView.loadRequest(request)
ซึ่งสามารถแสดงผลดังรูป

