Ios 是否在加载视图之前设置UITableItem属性?
我正试图改变一个修道院院长头衔的颜色 我在每个视图控制器的Ios 是否在加载视图之前设置UITableItem属性?,ios,objective-c,Ios,Objective C,我正试图改变一个修道院院长头衔的颜色 我在每个视图控制器的viewdiloads中都有以下代码: [self.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateSelected]; [self.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttr
viewdiload
s中都有以下代码:
[self.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName :
[UIColor whiteColor]} forState:UIControlStateSelected];
[self.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName :
[UIColor whiteColor]} forState:UIControlStateNormal];
这只有一半起作用,因为只有在加载视图后(因此,在至少点击一次选项卡栏项后),颜色才会从默认值更改。这不是我想要的行为,我希望应用程序启动后立即设置颜色
将代码放在视图控制器的initWithNibName:中根本不起作用
是否有任何方法可以从应用程序代表的didfishlaunchingwithoptions
中解决tabBarItem
s
更新:
下面我标记为正确的答案是有效的,不过我也找到了另一种方法,如果您想解决单个uitabaritem
s,这种方法效果更好。在选项卡栏控制器中,通过从Interface Builder创建出口或以编程方式将选项卡栏指定给指针后,您可以像这样寻址单个选项卡栏
项(对于选项卡栏
指向的UITabar):
等等
然后你可以做像这样的事情
[tab1 setTitleTextAttributes:]
以及各种其他内容。我的应用程序中有以下内容:Delegate Did Finish Launching with Options:
[[UITabBar appearance] setTintColor:[UIColor yellowColor]];
[[UITabBar appearance] setBarTintColor:[UIColor darkGrayColor]];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:10.0f], NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateSelected];
看看你的外表。
为选项卡栏和导航栏创建一个实用程序类,以显示所需的外观。然后从应用程序代理的didFinishLaunchingWithOptions调用该类。下面是一个让您开始学习的示例:
+ (void) setUpTabBarAppearance
{
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Your Font" size:15], UITextAttributeFont, [UIColor whiteColor], UITextAttributeTextColor, [UIColor clearColor], UITextAttributeTextShadowColor, nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ UITextAttributeTextColor : [UIColor greenColor] }forState:UIControlStateSelected];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]];
}
然后从应用程序代理的didFinishLaunchingWithOptions,调用:[实用程序设置选项卡外观];
此外,通过这种方式,您只需修改一次选项卡栏的外观,而不是在每个类中进行修改。导航控制器?你是说选项卡栏控制器吗?无论哪种方式,除了从选项卡项各自的视图控制器之外,我如何处理它们?UITabBar上有一个.items,但它没有任何外观属性。。。
+ (void) setUpTabBarAppearance
{
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Your Font" size:15], UITextAttributeFont, [UIColor whiteColor], UITextAttributeTextColor, [UIColor clearColor], UITextAttributeTextShadowColor, nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ UITextAttributeTextColor : [UIColor greenColor] }forState:UIControlStateSelected];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]];
}