UITabBar属性的设置
2017-04-27 本文已影响0人
为什么划船不靠桨
这些内容通常写在+initialize方法里
//首先拿到UITabBar
UITabBar * tab = [UITabBar appearance];
//背景颜色
//tab.barTintColor = [UIColor yellowColor];
//前景颜色
//tab.tintColor = [UIColor orangeColor];
//设置背景图片
[tab setBackgroundImage:[UIImage imageNamed:@"tabbar"]];
//设置透明度
tab.alpha = 0.3;
// UIControlStateNormal状态下的文字属性
NSMutableDictionary * dictionary = [NSMutableDictionary dictionary];
//文字颜色
dictionary[NSForegroundColorAttributeName] = [UIColor blackColor];
//文字大小
dictionary[NSFontAttributeName] = [UIFont systemFontOfSize:12];
// UIControlStateSelected状态下的文字属性
NSMutableDictionary * seleDictionary = [NSMutableDictionary dictionary];
seleDictionary[NSForegroundColorAttributeName] = [UIColor colorWithRed:255 / 256.0 green:255 / 256.0 blue:130 / 256.0 alpha:1];
UITabBarItem * itme = [UITabBarItem appearance];
[itme setTitleTextAttributes:dictionary forState:UIControlStateNormal];
[itme setTitleTextAttributes:seleDictionary forState:UIControlStateSelected];
//每一个控制器都有tabBarItem这个属性
childController.tabBarItem.image = [UIImage imageNamed:image];
childController.tabBarItem.selectedImage = [UIImage imageNamed:selectImage];
childController.tabBarItem.badgeValue = @"11";
//设置消息标题的字体大小
[item setBadgeTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:25]} forState:UIControlStateNormal];