iOS 7的UINavigationBar外观不工作的第一次…

我正在尝试更改iOS7应用程序中UINavigationBar的外观。 我正在做以下事情:

- (void)viewDidLoad { [super viewDidLoad]; m_sNumberToCall = @""; UIBarButtonItem * btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"IconHome.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(btHomeTouched:)]; self.navigationItem.leftBarButtonItem = btn; self.navigationController.navigationBar.translucent = YES; [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault]; 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:@"Helvetica-Bold" size:21.0], NSFontAttributeName, nil]]; } 

但是,我第一次介绍UITableViewController它是标准的iOS7导航栏,然后我按回家,再次呈现它,这是我的新面貌。

任何想法,为什么它不工作的第一次?

不要直接改变导航栏的外观。 外观只影响未来的实例,但不影响已经创build的实例。

更改:

 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault]; 

至:

 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault]; 

之前的答案只能帮助您处理背景图像,而不能处理title text attributes

你不需要改变你的代码,但你所要做的就是把它移动到

applicationDidFinishLaunchingWithOptions

在您的AppDelegate.m文件中。