ios - 在没有 xib 文件的情况下更改我的标签栏颜色

标签 ios objective-c uitabbarcontroller

我在更改选项卡栏颜色时遇到了麻烦,因为我没有使用 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/

相关文章:

ios - React-native-maps lite 模式不适用于 Ios 模拟器

iphone - 下载未完全完成时限制用户播放文件

ios - 如何从 UIView 子类调用 UIViewController?

objective-c - Xcode 错误 : Expected identifier

ios - 暂停返回后滚动 BG 丢失(iOS-SpriteKit-iphone)

iphone - 当 youtube 视频结束或按下完成按钮时 iOS 捕获事件

iphone - 在 iOS 上创建类似于饼图的东西

iphone - uiNavigationController 推送 View Controller 时出错

ios - "Presenting a controller modally within a nav controller within a tab bar controller"的问题

swift - 使用 UITabBarController 实例化 ViewController