【发布时间】: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