iOS 关于UITabBarItem 选中图片的颜色以及标题的颜色设置

本文详细介绍了如何在iOS应用中自定义Tab Bar的实现过程,包括创建多个控制器、设置Tab Bar的样式、调整Tab Bar项的外观及状态,并通过代码实例展示了具体操作步骤。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    Second *second = [[Second alloc] init];
    second.title = @"second";
    
    ViewController *aView = [[ViewController alloc] init];
    aView.title = @"aView";
    
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    NSArray *tabBarArray = [NSArray arrayWithObjects:[[UINavigationController alloc] initWithRootViewController:second], [[UINavigationController alloc] initWithRootViewController:aView], nil];
    tabBarController.viewControllers = tabBarArray;
    tabBarController.selectedIndex = 0;

    self.window.rootViewController = tabBarController;
    

    [[UITabBarItem appearance] setTitleTextAttributes:@{UITextAttributeFont : [UIFont systemFontOfSize:12],UITextAttributeTextColor : [UIColor redColor]} forState:UIControlStateNormal];
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{UITextAttributeFont : [UIFont systemFontOfSize:12],UITextAttributeTextColor : [UIColor blueColor]} forState:UIControlStateSelected];
    
    for (UITabBarItem *tabBarItem in tabBarController.tabBar.items)
    {
        tabBarItem.image = [[UIImage imageNamed:@"31.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        //设置显示图片原本的颜色
        tabBarItem.selectedImage = [[UIImage imageNamed:@"31_select.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        tabBarItem.title = @"11";
    }
    
    return YES;
}

代码附上




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值