如果想學(xué)習(xí)使用WKWebView,KINWebBrowser就是一個(gè)很不錯(cuò)的模塊,它使用iOS8的 WKWebView API編寫(xiě),同時(shí)在iOS 7上使用UIWebView來(lái)兼容,源碼也很簡(jiǎn)單,Source:https://github.com/dfmuir/KINWebBrowser.git,下面對(duì)其簡(jiǎn)單介紹一下
1.首先KINWebBrowserViewController must be contained in a UINavigationController.
Pushing to the navigation stack:
KINWebBrowserViewController*webBrowser= [KINWebBrowserViewControllerwebBrowser];[self.navigationController pushViewController:webBrowseranimated:YES];[webBrowserloadURLString:@"https://github.com/dfmuir/KINWebBrowser"];
Presenting Modally:
UINavigationController*webBrowserNavigationController = [KINWebBrowserViewController navigationControllerWithWebBrowser];[selfpresentViewController:webBrowserNavigationController animated:YEScompletion:nil];KINWebBrowserViewController *webBrowser = [webBrowserNavigationController rootWebBrowser];[webBrowser loadURLString:@"https://github.com/dfmuir/KINWebBrowser"];
兩種方式都必須包含UINavigationController.
2.效果圖
3.自定義
效果圖下面的按鈕都是作者寫(xiě)好的,如果不符合我們的需求我們可以修改源碼進(jìn)行自定義或者干脆隱藏掉.
按鈕自定義部分
- (void)setupToolbarItems {NSBundle*bundle = [NSBundlebundleForClass:[selfclass]];self.refreshButton= [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:selfaction:@selector(refreshButtonPressed:)];self.stopButton= [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:selfaction:@selector(stopButtonPressed:)];UIImage*backbuttonImage = [UIImageimageWithContentsOfFile: [bundle pathForResource:@"backbutton"ofType:@"png"]];self.backButton= [[UIBarButtonItemalloc] initWithImage:backbuttonImage style:UIBarButtonItemStylePlain target:selfaction:@selector(backButtonPressed:)];UIImage*forwardbuttonImage = [UIImageimageWithContentsOfFile: [bundle pathForResource:@"forwardbutton"ofType:@"png"]];self.forwardButton= [[UIBarButtonItemalloc] initWithImage:forwardbuttonImage style:UIBarButtonItemStylePlain target:selfaction:@selector(forwardButtonPressed:)];self.actionButton= [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:selfaction:@selector(actionButtonPressed:)];self.fixedSeparator= [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nilaction:nil];self.fixedSeparator.width=50.0f;self.flexibleSeparator= [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nilaction:nil];}
如果想把下面的所有按鈕隱藏,可以通過(guò)下面的方法實(shí)現(xiàn)
- (void)viewWillAppear:(BOOL)animated {? ? [superviewWillAppear:animated];? ? [self.navigationControllersetNavigationBarHidden:NOanimated:YES];? ? [self.navigationControllersetToolbarHidden:NOanimated:YES];? ? [self.navigationController.navigationBaraddSubview:self.progressView];? ? [selfupdateToolbarState];}