我在更改选项卡栏颜色时遇到了麻烦,因为我没有使用 xib 文件,不知何故我的代码结构对我一点帮助都没有,请告诉我是否需要从头开始重写整个内容,但是我如果不需要,我将不胜感激 ^_^
这是我的单 View 应用程序的 appDelegate 文件,在这里我创建了带有与每个选项卡关联的导航栏的选项卡栏,然后显示它们
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
self.firstTab = [[FirstTab alloc] initWithNibName:nil bundle:NULL];
self.firstNavigationController = [[UINavigationController alloc] initWithRootViewController:self.firstTab];
self.thirdTab = [[ThirdTab alloc] initWithNibName:nil bundle:NULL];
self.thirdNavigationController = [[UINavigationController alloc] initWithRootViewController:self.thirdTab];
self.tab2 = [[newsecViewController alloc] initWithNibName:@"newsecViewController" bundle:NULL];
self.tab2NavigationController = [[UINavigationController alloc] initWithRootViewController:self.tab2];
self.tab2.view.backgroundColor = [UIColor purpleColor];
//NSArray *tabs = [[NSArray alloc] initWithObjects:self.firstTab, self.secondTab, self.thirdTab, nil];
NSArray *tabBars = [[NSArray alloc] initWithObjects:self.firstNavigationController, self.tab2NavigationController, self.thirdNavigationController, nil];
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController setViewControllers:tabBars];
[self.window addSubview:self.tabBarController.view];
这是我的一个标签的代码示例
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self != nil) {
self.title = @"Second";
self.tabBarItem.image = [UIImage imageNamed:@"triangle.png"];
}
return self;
感谢大家的帮助...
最佳答案
使用标签栏的 tintColor 属性。它适用于 iOS 5.0 及更高版本。
[tabBarController.tabBar setTintColor:[UIColor purpleColor]];
关于ios - 在没有 xib 文件的情况下更改我的标签栏颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19598465/