ios - 更改导航栏颜色

标签 ios iphone objective-c ios7 uinavigationbar

我正在开发 iOS 7 应用程序。我的导航栏过去如下图所示:

enter image description here

但是添加这段代码后

self.edgesForExtendedLayout = UIRectEdgeNone;

导航车颜色变暗,如下图所示:。 enter image description here

我们如何让导航栏像第一张图片一样保持更亮,同时保留上面的代码?

最佳答案

默认情况下,导航栏的半透明属性设置为YES。
此外,所有导航栏都应用了系统模糊。在此设置下,iOS 7 倾向于降低条形颜色的饱和度。

半透明设置差异

Difference Translucent settings 设置色调颜色 Setting Tint Color

关闭半透明设置

Turn off translucent setting

将此代码放入 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/

相关文章:

ios - 在 UITableView 中, "visibleCells"的代表是什么?

iphone - CoreMotion - 磁场始终为 0

iOS 4.3.2 用户报告应用程序在启动时崩溃

ios - Xcode仪器: Memory Terms Live Bytes and Overall Bytes (Real Memory) confusion

ios - 如何以编程方式将 JSON 数组从 UITableViewCell 传递到新的 UIViewController?

iOS9 GoogleAnalytics 和 NSAppTransportSecurity

ios - Swift 3 - 动画

ios - [NSObject : AnyObject] and AnyObject in swift 有什么区别

iphone - 在 iOS 7 中绕过 Apple Captive Network Assistant 登录

objective-c - 一个奇怪的 C 字符串和 NSString 比较问题