What is the size of the image for UINavigationBar

≡放荡痞女 提交于 2019-12-11 15:55:27

问题


There are three simulator or iPhone devices, as given below

iPhone

iPhone (Retina 3.5 inch)

iPhone (Retina 4 inch)

I want to implement the following method, for navigation bar.

- (UINavigationController *)navigationController {

    nav = [[UINavigationController alloc]
           initWithRootViewController:[self demoController]];

    // If Iphone/iPod Touch
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        // If iPhone 5 or new iPod Touch

        NSLog(@"The height is %f ", [UIScreen mainScreen].bounds.size.height );

        NSLog(@"The width is %f ", [UIScreen mainScreen].bounds.size.width);


        if([UIScreen mainScreen].bounds.size.height == 568){
            [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav.png"] forBarMetrics: UIBarMetricsDefault];
        } else{
            // Regular iPhone
            [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_classic.png"] forBarMetrics: UIBarMetricsDefault];

        }
    }

    return nav;

}

I want to know proper size of Navigation image, nav.png, and condition, so that i can work for all three devices.

As I used 320x44 for nav classic, but it looks small in device iPhone (Retina 3.5 inch) So, As I use nav.png for all, its looks bigger iPhone

1. What are proper sizes of UINavigationBar?

2. What is proper logic to use them?

Thanks


回答1:


There's no difference in the size of the navigation bar for iphone 3.5 retina and iphone 4 retina. The real size of the image for this retina devices is 640x88. You can also made two images for the navigation bar one at 320x44 (for non retina devices) and one at 640x88. You have to name this image something like NavImage.png and NavImage@2x.png , in this way the os will automaticcaly use the correct image.




回答2:


[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"NavBar-iPhone.png"]forBarMetrics:UIBarMetricsDefault];

used this code for setting background image to navigation bar no worry about size iphone 3.5,iphone 4 it will automatically adjust.



来源:https://stackoverflow.com/questions/18841469/what-is-the-size-of-the-image-for-uinavigationbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!