iOS中设置导航栏的背景颜色和标题字体以及颜色,以及tabBarItem的图片和字体颜色的设置

翻了一下以前的博客,发现之前没有记录这一知识点,庆祝中华人民共和国抗战胜利暨反法西斯胜利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];
}




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值