在ios8上使用UITabbarController,对于UITabbarController的方法,有些已经不能用了,下面把最新的方法介绍如下:
UIImage * normalImage = [[UIImage imageNamed:@"normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage * selectImage = [[UIImage imageNamed:@"normalSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem * tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页" image:normalImage selectedImage:selectImage];
self.tabBarItem = tabBarItem;
UIImage * selectImage = [[UIImage imageNamed:@"normalSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem * tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页" image:normalImage selectedImage:selectImage];
self.tabBarItem = tabBarItem;
用下面的代码,可以对字体的颜色进行设定成自己想要的颜色。
设置默认颜色
设置默认颜色
[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
点击时候的字体颜色
[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:186/255.0f green:132/255.0f blue:194/255.0f alpha:1]} forState:UIControlStateSelected];
点击时候的图片颜色(看需求设置)
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:186/255.0f green:132/255.0f blue:194/255.0f alpha:1]];
点击时候的字体颜色
[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:186/255.0f green:132/255.0f blue:194/255.0f alpha:1]} forState:UIControlStateSelected];
点击时候的图片颜色(看需求设置)
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:186/255.0f green:132/255.0f blue:194/255.0f alpha:1]];