Translucent , setStatusBarStyle, UIWebView

2019-08-10 08:18发布

enter image description hereI'm working on the UIWebView and what I want is for the webView not to over rap the view.

so here is the question. I set the UIWebView ,and the status bar is overlaid over the content. How can I handle this? I coded as when I made the UIImage view, but at that time there is the navigation bar, and it worked well.

Also I did setFrame:CGRectMake(0, 20).... but also doesn't work. why the [ setFrame]; method doesn't work? Any ideas please.

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault];
    [self.webView setFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height)];

    NSURL *myURL = [NSURL URLWithString:@"http://www.amazon.com"];
    NSURLRequest *myURLReq = [NSURLRequest requestWithURL:myURL];
    [self.webView loadRequest:myURLReq];






}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


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

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

}


@end

UPDATE: I switched off the Auto-layout and change setFrame:CGRectMake(0, 20) and now they are not overlaid. But I wonder why we need to set this? If I set the status bar translucent , it makes sense. But I set it as the default, which is supposed to start to draw the screen right below the status bar at (0,20).

2条回答
我只想做你的唯一
2楼-- · 2019-08-10 09:02

Add following code in your viewDidLoadMethod :

 if( [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-08-10 09:19

Try this one

- (void)viewDidLoad
{
     [super viewDidLoad];

  // Do any additional setup after loading the view, typically from a nib.


    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault];

    [self.webView setFrame:CGRectMake(0.0, 20.0, self.view.frame.size.width, self.view.frame.size.height)];

     NSURL *myURL = [NSURL URLWithString:@"http://www.amazon.com"];

     NSURLRequest *myURLReq = [NSURLRequest requestWithURL:myURL];
     [self.webView loadRequest:myURLReq];

}

Your autosize masks should look like this.

Your autosize masks should look like this

Final Output:

enter image description here

查看更多
登录 后发表回答