中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

UIWebView的使用,簡(jiǎn)單瀏覽器的實(shí)現(xiàn)

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用

#import "ViewController.h"

@interface ViewController () <UIWebViewDelegate>

@property(nonatomic,weak)UIWebView* web;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self _setTextField];
    
    [self _loadWebView];
    
}

#pragma mark - 設(shè)置輸入框
- (void)_setTextField{
    self.tf.clearButtonMode=UITextFieldViewModeWhileEditing;
}

#pragma mark - 加載WebView
- (void)_loadWebView{
    UIWebView* web=[[UIWebView alloc] init];
    web.frame=CGRectMake(0,self.view.frame.size.height,self.view.frame.size.width,self.view.frame.size.height-42 );
    self.web=web;
    web.delegate=self;
    [self.view addSubview:web];
    
    
}

#pragma mark - 放棄第一響應(yīng)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.tf resignFirstResponder];
    
}

#pragma mark - Action
- (IBAction)backAction:(id)sender {
    [self.web goBack];
//    self.web.frame=CGRectMake(0,self.view.frame.size.height,self.view.frame.size.width,self.view.frame.size.height-42 );
    
}

- (IBAction)forwardAction:(id)sender {
    [self.web goForward];
    self.web.frame=CGRectMake(0,20,self.view.frame.size.width,self.view.frame.size.height-50);
}

- (IBAction)undoAction:(id)sender {
    [self.web stopLoading];
}

- (IBAction)refreshAction:(id)sender {
    [self.web reload];
}

- (IBAction)searchAction:(id)sender {
    [self.tf resignFirstResponder];
    
    self.web.frame=CGRectMake(0,20,self.view.frame.size.width,self.view.frame.size.height-60);

    [self _sendRequest];
}

#pragma mark - UIWebViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    
    
    return YES;
}

- (void)webViewDidStartLoad:(UIWebView *)webView{

}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
//    NSLog(@"%d===%d",[webView canGoBack],[webView canGoForward]);
    self.backBt.enabled=[webView canGoBack];
    self.forwardBt.enabled=[webView canGoForward];
    self.refresh.enabled=([webView canGoBack] ||[webView canGoForward]);
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    NSLog(@"%@",error);

}

- (void)_sendRequest{
    //http://www.baidu.com
    NSURL* url=[NSURL URLWithString:self.tf.text];
    NSURLRequest* request=[NSURLRequest requestWithURL:url];
    [self.web loadRequest:request];
}

@end

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:ASI框架使用全集講解

下一篇:iOS get請(qǐng)求的block方法