Чтобы узнать фактические цвета для UITabBarItem, даже не обращаясь к API внешнего вида, прежде чем использовать следующий код. Он запрашивает иерархию представлений и использует первую и вторую кнопку для определения фактического UIColor. Для IOS9 он дает «UIDeviceRGBColorSpace 0 0,478431 1 1» (# 007aff в шестнадцатеричном формате) для выделенного цвета и «UIDeviceWhiteColorSpace 0.572549 1» (# 929292 в шестнадцатеричном формате) для неактивного цвета. Это может измениться, конечно, в будущих версиях. Чтобы получить конкретный цвет для элемента с tintColors, азартность и т. Д., Используйте findTabBarLabel() для фактического UITabBar.
static UILabel* findTabBarLabel(UITabBar* tb,NSString* text)
{
for (UIView* btn in tb.subviews) {
if (![btn isKindOfClass:NSClassFromString(@"UITabBarButton")]) {continue;}
for (UIView* sv in btn.subviews) {
if (![sv isKindOfClass:NSClassFromString(@"UITabBarButtonLabel")]) {continue;}
UILabel* l=(UILabel*)sv;
if ([text isEqualToString:l.text]) {
return l;
}
}
}
return nil;
}
static void retrieveTabBarSystemColors()
{
UITabBarController* tc=[[UITabBarController alloc] init];
UITabBarItem* it1=[[UITabBarItem alloc] initWithTitle:@"foo" image:nil tag:1];
UIViewController* vc1=[[UIViewController alloc] init];
vc1.tabBarItem=it1;
UITabBarItem* it2=[[UITabBarItem alloc] initWithTitle:@"bar" image:nil tag:2];
UIViewController* vc2=[[UIViewController alloc] init];
vc2.tabBarItem=it2;
[email protected][vc1,vc2];
UITabBar* tb=tc.tabBar;
UILabel* label1=findTabBarLabel(tb,@"foo");
NSLog(@"Tab bar item active:%@",label1.textColor.description);
UILabel* label2=findTabBarLabel(tb,@"bar");
NSLog(@"Tab bar item inactive color:%@",label2.textColor.description);
}
Как вы устанавливаете цвет? – Dash