Um die tatsächlichen Farben für UITabBarItem zu ermitteln, müssen Sie den folgenden Code verwenden, auch wenn Sie keine Appearance-API aufrufen. Es fragt die Ansichtshierarchie ab und verwendet die erste und die zweite Schaltfläche, um den tatsächlichen UIColor herauszufinden. Für IOS9 gibt es "UIDeviceRGBColorSpace 0 0.478431 1 1" (# 007aff in hex) für die selectedColor und "UIDeviceWhiteColorSpace 0.572549 1" (# 929292 in hex) für die inactiveColor. Das könnte sich natürlich in zukünftigen Versionen ändern. Um eine konkrete Farbe für ein Objekt mit TintColors, Appearance usw. zu erhalten, verwenden Sie findTabBarLabel() für die tatsächliche 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);
}
Wie stellen Sie die Farbe ein? – Dash