Ios7 navigation bar adaptation

Source: Internet
Author: User

The navigation bar is often used during ios ui development. The default style is relatively simple, so you often need to modify the style of the navigation bar.

Ios4:

- (void)drawRect:(CGRect)rect {    UIImage *image = [UIImage imageNamed:@"navbar_bg.png"];    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];    return;}

After ios5:

 if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{  [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_bg.png"] forBarMetrics:UIBarMetricsDefault];}

 

Ios7, because the navigation bar will be extended to the system status bar, so the Image Height needs to be increased by 20 PX. If there is no additional processing, a black bar in the status bar may appear.

        if (7.0 <= [[[UIDevice currentDevice] systemVersion] floatValue])        {            [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_bg_7.png"] forBarMetrics:UIBarMetricsDefault];        }        else        {            [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_bg.png"] forBarMetrics:UIBarMetricsDefault];        }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.