欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

ios 简单的webview跳转

程序员文章站 2022-12-30 23:11:11
#import “RwebViewController.h”#import #import “Masonry.h”@interface RwebViewController ()@end@implementation RwebViewController(void)viewDidLoad {[super viewDidLoad];// Do any additi...

#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

相关标签: ios webview