Duaan
Duaan

Reputation: 609

What is the size of the image for UINavigationBar

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

Upvotes: 0

Views: 7620

Answers (2)

cri1682
cri1682

Reputation: 442

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 [email protected] , in this way the os will automaticcaly use the correct image.

Upvotes: 1

Jitendra
Jitendra

Reputation: 5081

[[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.

Upvotes: 0

Related Questions