我正在尝试更改标签栏项目的字体颜色。我正在使用这篇文章中的代码:
change tabbar text color,iPhone
我的代码如下:
if ([self.tabBarItem respondsToSelector:@selector(setTitleTextAttributes:)]) {
NSLog(@"yes");
[self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
darkGreen, UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
}
else {
NSLog(@"no");
}
respondsToSelector总是返回no,我对如何修复它感到困惑。此代码块位于viewDidLoad中,该类是UITabBarController的子类。
有什么想法吗?
答案 0 :(得分:0)
此方法setTitleTextAttributes:
根本不存在,该方法的正确签名为setTitleTextAttributes: forState:
if ([self.tabBarItem respondsToSelector:@selector(setTitleTextAttributes: forState:)]) {
NSLog(@"yes");
[self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
darkGreen, UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
}
else {
NSLog(@"no");
}