這裏是我如何從UIWebView轉換爲WKWebView。
注意:沒有像UIWebView那樣的屬性,您可以拖動到您的 故事板,您必須以編程方式執行此操作。
確保您將WebKit/WebKit.h導入到您的頭文件中。
這是我的頭文件:
#import <WebKit/WebKit.h>
@interface ViewController : UIViewController
@property(strong,nonatomic) WKWebView *webView;
@property (strong, nonatomic) NSString *productURL;
@end
這是我實現文件:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.productURL = @"http://www.URL YOU WANT TO VIEW GOES HERE";
NSURL *url = [NSURL URLWithString:self.productURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
_webView = [[WKWebView alloc] initWithFrame:self.view.frame];
[_webView loadRequest:request];
_webView.frame = CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:_webView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
來源
2014-12-04 19:27:51
Ali
也許這將幫助你:http://floatlearning.com/2014/12/one-webview -to-rule-them-all/ – Koen 2015-01-31 22:53:30
http://blog.initlabs.com/post/100113463211/wkwebview-vs-uiwebview – jose920405 2015-11-19 14:15:37
Swift v WKWebView的ersion:https://iosdevcenters.blogspot.com/2016/05/creating-simple-browser-with-wkwebview.html – 2016-05-27 07:40:54