3

使用 iOS 7 SDK 构建我的应用程序会改变导航栏及其按钮的外观:

导航栏比较

上图显示了在使用 iOS 6 的设备上运行时的样子,下图显示了在使用 iOS 7 的设备上运行的相同应用程序。

导航栏是使用背景图像创建的:

UIImage *navigationBarBackgroundImage = [[UIImage imageNamed:@"MyTopNavigationBackground"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 4, 0)];

UINavigationBar *bar = [UINavigationBar appearanceWhenContainedIn:[MyNavigationController class], nil];
[bar setBackgroundImage:navigationBarBackgroundImage forBarMetrics:UIBarMetricsDefault];
[bar setTintColor:[UIColor colorWithRed:0.17 green:0.62 blue:0.23 alpha:1.0]];

左栏按钮由以下方式创建:

- (UIBarButtonItem *)slideoverMenuBarButtonItem {
    return [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bar_button_icon_menu.png"]
                                        style:UIBarButtonItemStylePlain
                                       target:self
                                       action:@selector(slideoverMenu)];
}

我更关心按钮外观发生了什么。处理向新 iOS 7 外观过渡的“最佳实践”是什么?

4

3 回答 3

5

Navigation bar background:

You need to use a stretchable image to fill the navigation bar. Because your image appears to be a fairly simple gradient, something like this should get you close:

[[UINavigationBar appearance] setBackgroundImage:[navigationBarBackgroundImage stretchableImageWithLeftCapWidth:0 topCapHeight:0]];

and your background image becomes a 1w x 64h png.

Bar button image:

use [UIImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

 UIImage *buttonImage = [UIImage imageNamed:@"bar_button_icon_menu.png"];
 return [[UIBarButtonItem alloc] initWithImage:[buttonImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                            style:UIBarButtonItemStylePlain
                                           target:self
                                           action:@selector(slideoverMenu)];

}

as the default behavior is to paint your non-transparent image pixels with the application tint color, "always original" mode will prevent that from happening.

于 2013-09-26T21:20:34.340 回答
1

Since the status bar is now part of the navigation bar, your custom navigation bar background image should be able to stretch across the status bar and navigation bar, or should be high enough for both.

于 2013-09-26T21:20:21.830 回答
0

按钮在同一个地方,但你的导航栏向上移动。大概是试图阻止这种“想要全屏”的尝试。

请参阅项目定义页面 General -> Deployment info -> Status bar style 或在代码中(如果您覆盖它)。

此外,iOS 属性 setSelectedImage 中还有新的,也检查一下

于 2013-09-26T21:03:53.200 回答