翻了一下以前的博客,发现之前没有记录这一知识点,庆祝中华人民共和国抗战胜利暨反法西斯胜利70周年阅兵放假三天(中国威武,犯我中华者,虽远必诛),假期在家用Swift研究微信的时候突然想到这个东西,就把代码粘一下吧,当然这里粘的是OC的代码,Swift的代码在家里自己电脑上,其实方法的关键字都差不多,就是OC与Swift语法不太一样而已。
//设置导航栏的背景颜色和标题字体以及颜色
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0) {
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, [UIFont fontWithName:@ "HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
}
}
//设置tabBarItem的图片和字体颜色的
//设置tabBarItem未选中状态和选中状态下的图片,
UIImage *settingsImg = [UIImage imageNamed:@"设置当前icon"];
settingsImg = [settingsImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//原图片显示,不失真,不会变成系统默认蓝色
[_settingsVC.tabBarItem setFinishedSelectedImage:settingsImg
withFinishedUnselectedImage:[UIImage imageNamed:@"设置icon"]];
[self unSelectedTapTabBarItems:_settingsVC.tabBarItem];
[self selectedTapTabBarItems:_settingsVC.tabBarItem];
//设置tabBarItem没选中时的字体自颜色
-(void)unSelectedTapTabBarItems:(UITabBarItem *)tabBarItem
{
[tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont systemFontOfSize:14], UITextAttributeFont,[UIColor grayColor],UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
}
//设置tabBarItem选中时的字体颜色
-(void)selectedTapTabBarItems:(UITabBarItem *)tabBarItem
{
[tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont systemFontOfSize:14],
UITextAttributeFont,[UIColor redColor],UITextAttributeTextColor,
nil] forState:UIControlStateSelected];
}