Colors IOS7 UINavigationBar黑色背景

Colors IOS7 UINavigationBar黑色背景,colors,background,uinavigationbar,ios7,Colors,Background,Uinavigationbar,Ios7,有人知道我如何在IOS7中将UINavigationBar变成纯黑色吗?默认为白色,我需要黑色。以下是一种通过编程创建黑色UIImage并将其设置为UINavigationBar外观的方法: UIView *background = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 568, 44)]; background.backgroundColor = [UIColor blackColor]; UIGraphicsBeginImageCont

有人知道我如何在IOS7中将UINavigationBar变成纯黑色吗?默认为白色,我需要黑色。

以下是一种通过编程创建黑色UIImage并将其设置为UINavigationBar外观的方法:

UIView *background = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 568, 44)];
background.backgroundColor = [UIColor blackColor];
UIGraphicsBeginImageContext(background.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[background.layer renderInContext:context];
UIImage *backgroundImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();        

[[UINavigationBar appearance] setBackgroundImage:backgroundImage
                                           forBarMetrics:UIBarMetricsDefault];

我自己找到的。进入情节提要设计器,选择ViewController,转到属性检查器,并将顶部栏从推断更改为“不透明黑色导航栏”

如果您仅针对iOS 7,则可以使用:

[[UINavigationBar appearance] setBarTintColor:(UIColor *)];

不幸的是,Interface Builder的可能副本只提供了一个模拟的外观(看看标签,上面写着“模拟度量”)。您需要在代码(每个ViewController)或info.plist(每个应用程序)中进行设置。