【发布时间】:2014-11-12 17:53:04
【问题描述】:
我认为我的标题是我正在寻找的。所以,我有一个带有 4 个视图控制器的标签栏。我开始在情节提要中配置我的应用程序,并从那里配置了我的标签栏控制器。我也已经在我的 appdelegate 文件中声明了视图控制器的名称。我的问题如下。我可以在标签栏控制器的中间添加一个按钮吗?我对此进行了很多搜索,但没有找到完整的解决方案。我可以使用故事板将我的视图控制器连接到选项卡栏,还可以使用应用程序委托将该按钮声明到选项卡栏的中心吗?请帮忙。到目前为止,这是我在应用程序委托文件中的代码(其他任何内容都在情节提要中,突出连接到 tabbarcontroller 的视图控制器):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Assign tab bar item with titles
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
tabBarController.selectedIndex = 1;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:3];
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:4];
tabBarItem1.title = @"Tab1";
tabBarItem2.title = @"Tab2";
tabBarItem3.title = @"Tab3";
tabBarItem4.title = @"Tab4";
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"maps_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"maps.png"]];
// Change the tab bar background
UIImage* tabBarBackground = [UIImage imageNamed:@"TAPBARBGR.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]];
// Change the title color of tab bar items
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
UIColor *titleHighlightedColor = [UIColor colorWithRed:153/255.0 green:192/255.0 blue:48/255.0 alpha:1.0];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
titleHighlightedColor, UITextAttributeTextColor,
nil] forState:UIControlStateHighlighted];
return YES;
}
谢谢。
【问题讨论】:
标签: ios objective-c iphone xcode