iOS常用方法——UIWebView全屏显示的实现

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/aaaaazq/article/details/80930844

项目中加载webView,导航栏由web端做的话,客户端就需要隐藏掉导航栏。这个时候显示出来的页面,在顶部会出现状态栏为空白的问题。底部也会多出空白,即:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    UIWebView * view = [[UIWebView alloc] initWithFrame:self.view.frame];
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];
}

效果如图:
这里写图片描述
这里写图片描述
只需要将代码做如下修改,就可以解决以上问题,实现全屏:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    UIWebView * view = [[UIWebView alloc] initWithFrame:self.view.frame];
    view.backgroundColor = [UIColor redColor];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11) {
        view.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    [self.view addSubview:view];
}

亲试有效的哦~注意要判断一下系统的版本,scrollView.contentInsetAdjustmentBehavior这个属性时iOS11后添加的,如果版本号没到11,可能会崩溃。

猜你喜欢

转载自blog.csdn.net/aaaaazq/article/details/80930844