之前我用这个代码使用了一个导航 Controller :
self.navigationItem.title = @"News";
现在我遇到的问题是我不再需要导航 Controller ,因为我正在使用页面 Controller 进行导航。现在我添加了一个导航栏,但它不再使用此代码更改标题。
还有我怎样才能改变背景颜色?
最佳答案
在 iOS 7 中使用 didFinishLaunchingWithOptions
编写以下代码
if ([[UINavigationBar class] respondsToSelector:@selector(appearance)])
{
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed: 4.0/255.0 green:173.0/255.0 blue:214.0/255.0 alpha:1.0f ]]; //// change background color of navigationBar
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; /// set backButton color of navigation bar
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}]; // set title color
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal]; /// set all barButton item color
self.navController.navigationBar.translucent = NO;// set translucent NO
}
根据您的要求使用。
关于ios - 如何更改自定义 NavigationItem 标题和背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23430394/