ios 简单的webview跳转
#import “RwebViewController.h”
#import <WebKit/WebKit.h>
#import “Masonry.h”
@interface RwebViewController ()<WKUIDelegate,WKNavigationDelegate>
@end
@implementation RwebViewController
-
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self initUI];//返回按钮
UIButton *backlog = [UIButton buttonWithType:UIButtonTypeCustom];
[backlog setTitle:@“返回” forState:UIControlStateNormal];
[backlog setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
backlog.frame = CGRectMake(10, 40, 52, 30);
[backlog addTarget:self action:@selector(backlogAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backlog];
}
-
(void)backlogAction{
[self.navigationController popViewControllerAnimated:YES];
}
-(void)initUI
{
WKWebView *webv=[[WKWebView alloc]init];
webv.UIDelegate=self;
webv.navigationDelegate=self;
[self.view addSubview:webv];
//适配
[webv mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view).with.offset(0);
make.top.equalTo(self.view).with.offset(58);
make.right.equalTo(self.view).with.offset(0);
make.bottom.equalTo(self.view).with.offset(88);
}];
NSURL *url=[NSURL URLWithString:@"https://www.baidu.com/"];
NSURLRequest *reqt=[[NSURLRequest alloc]initWithURL:url];
[webv loadRequest:reqt];
}
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
{
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
}
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error
{
}
@end
本文地址:https://blog.csdn.net/wuyan9527/article/details/107480929