我想在Watchkit中按下按钮以显示URL中的图像。鉴于Watchkit中没有UIWebView,我的假设是我需要通过监视按钮触发,为手机上的URL加载UIWebView,存储在UIImage中,我可以将其传回手表进行显示。首先是最好的策略,其次任何人都可以帮助我在Swift中存储来自UIWebView的UIImage的代码吗?
手机的ViewController:
import UIKit
class ViewController: UIViewController {
var URLPath = "myURL.jpeg"
@IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
loadAddressURL()
}
//to fit webpage within webView
override func viewDidAppear(animated: Bool) {
webView.frame = UIScreen.mainScreen().bounds
webView.center = self.view.center
webView.scalesPageToFit = true
}
func loadAddressURL () {
let url = NSURL(string: URLPath)
let requestObj = NSURLRequest(URL: url!)
webView.loadRequest(requestObj)
}
}