4

我正在尝试找到一种方法来修改 UINavigationBar 的样式而不使用图像。我想创建一个纯色的平面 UINavigationBar。我唯一的选择是继承 UINavigationBar 并自己绘制完整的 NavigationBar 吗?我的目标是运行 iOS 6.0 的 iPhone。

4

1 回答 1

5

您可以使用UINavigationBar appearance

在这里,根据需要编辑颜色的 rgb 值

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:1/256.0 green:96/256.0 blue:149/256.0 alpha:1.0]];

 return YES;

}

注意:[[UIBarButtonItem appearance]这不会影响 bar button items ,如果你也想改变按钮,你必须看看

[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:126/256.0 green:181/256.0 blue:55/256.0 alpha:1.0]];
于 2013-04-30T18:05:24.040 回答