自定义tabBarItem选中和未选中的显示效果

以下代码是在TabBarViewController的ViewControllers的其中一个ViewController的viewDidLoad中写的!!!

 

    UIImage *image = [UIImage imageNamed:@"Heart"];

    //item未选中状态时,image不使用tintColor的颜色

    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

 

    //添加tabbarItem

    UITabBarItem *tabbarItem = [[UITabBarItem alloc] initWithTitle:@"育儿搜" image:image selectedImage:image];

 

    //设置item未选中状态时,title的颜色

    [tabbarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];

    self.tabBarItem = tabbarItem;

posted @ 2015-11-30 17:35  大big  阅读(696)  评论(0)    收藏  举报