我正在开发 iOS 7 应用程序。我的导航栏过去如下图所示:
但是添加这段代码后
self.edgesForExtendedLayout = UIRectEdgeNone;
导航车颜色变暗,如下图所示:。
我们如何让导航栏像第一张图片一样保持更亮,同时保留上面的代码?
最佳答案
默认情况下,导航栏的半透明属性设置为YES。
此外,所有导航栏都应用了系统模糊。在此设置下,iOS 7 倾向于降低条形颜色的饱和度。
半透明设置差异
设置色调颜色
关闭半透明设置
将此代码放入 appDelegate.m 中的 didFinishLaunchingWithOptions 中:
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
if (floor(NSFoundationVersionNumber) >= NSFoundationVersionNumber_iOS_6_1)
{
// Load resources for iOS 7 or later
// To change the background color of navigation bar
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];
// To change the color of back button
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
}
关于ios - 更改导航栏颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21621750/