【问题标题】:Setting TabBar Item title and Image on Selection in XCode 6.4在 XCode 6.4 中设置 TabBar 项目标题和图像
【发布时间】:2015-10-18 19:55:00
【问题描述】:

我正在使用 xcode 6.4 并使用情节提要来设置标签栏控制器项目及其图像。

问题 1- 在标签栏项目选择的情节提要中,已经有栏项目和图像选择的选项。我在两个字段上都分配了图像,但图像在选择时没有改变。只有默认(黑色)图像存在。

我已经提到了这个Link。那么默认(黑色)也存在

问题 2- 在情节提要中,我已在 Bar Item 和 Image Selection 上分配了所有图像,并使用了给定的代码,然后标题在标签栏项目中不可见。只有图像在选择上工作正常。

代码-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Assign tab bar item with titles
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
UITabBarItem *tabBarItem5 = [tabBar.items objectAtIndex:4];

tabBarItem1.title = @"Home";
tabBarItem2.title = @"Search";
tabBarItem3.title = @"Cart";
tabBarItem4.title = @"Account";
tabBarItem5.title = @"More";



[tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"HomeSelected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

[tabBarItem2 setSelectedImage:[[UIImage imageNamed:@"SearchOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

[tabBarItem3 setSelectedImage:[[UIImage imageNamed:@"CartOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

[tabBarItem4 setSelectedImage:[[UIImage imageNamed:@"ProfileOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

[tabBarItem5 setSelectedImage:[[UIImage imageNamed:@"MoreTabOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];



// Change the tab bar background
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.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], NSForegroundColorAttributeName,
                                                   nil] forState:UIControlStateNormal];
UIColor *titleHighlightedColor = [UIColor colorWithRed:255.0/255.0 green:109.0/255.0 blue:0.0/255.0 alpha:1.0];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   titleHighlightedColor, NSForegroundColorAttributeName,
                                                   nil] forState:UIControlStateHighlighted];
return YES;
}

我看过 iOS Docs,但在这些问题上找不到任何有用的更新。请更新我。

【问题讨论】:

    标签: ios objective-c uitabbarcontroller


    【解决方案1】:

    您应该创建自定义标签栏

    有用的链接:http://swiftiostutorials.com/tutorial-custom-tabbar-storyboard/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-12
      • 1970-01-01
      • 1970-01-01
      • 2010-12-11
      • 2015-11-14
      • 2012-05-21
      • 2021-03-10
      • 2020-08-20
      相关资源
      最近更新 更多