【问题标题】:What is the size of the image for UINavigationBarUINavigationBar 的图像大小是多少
【发布时间】:2013-09-17 04:46:34
【问题描述】:

一共有三个模拟器或 iPhone 设备,如下所示

iPhone

iPhone (Retina 3.5 inch)

iPhone (Retina 4 inch)

我想为导航栏实现以下方法。

- (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;

}

我想知道导航图像、nav.png 和条件的适当大小,以便我可以在所有三种设备上工作。

因为我使用 320x44 进行经典导航,但在设备中看起来很小 iPhone(Retina 3.5 英寸) 所以,当我使用 nav.png 时,它看起来更大 iPhone

1. UINavigationBar 的合适尺寸是多少?

2。使用它们的正确逻辑是什么?

谢谢

【问题讨论】:

    标签: iphone ios navigationbar


    【解决方案1】:

    iphone 3.5 Retina 和 iphone 4 Retina 的导航栏大小没有区别。此 Retina 设备的实际图像尺寸为 640x88。您还可以为导航栏制作两张图像,一张为 320x44(用于非视网膜设备),一张为 640x88。您必须将此图像命名为 NavImage.png 和 NavImage@2x.png ,这样操作系统将自动使用正确的图像。

    【讨论】:

      【解决方案2】:
      [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"NavBar-iPhone.png"]forBarMetrics:UIBarMetricsDefault];
      

      使用此代码将背景图像设置为导航栏不用担心大小 iphone 3.5,iphone 4 会自动调整。

      【讨论】:

      • NavBar-iPhone.png 这张图片的尺寸是多少?
      • 它不起作用,请在最后查看并编辑答案,iphone 4 和 iphone 5 ratina,与 320x44 不匹配,
      • 所以使用大尺寸图片并尝试使用自动布局。
      • 感谢您提供如此无用的建议。如果您没有准确回答,则不得发布不相关的答案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-11
      • 2011-04-21
      • 2013-08-06
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多