我对自定义 UITabBarItem 有疑问
首先可以下载我的代码demo
现在,我在 MyAppDelegate 的自定义 UITabbarcontroller 是:
-(void)configureiPhoneTabBar
{
tabViewController = (UITabBarController *)self.window.rootViewController;
UIViewController *controller1 = [[tabViewController viewControllers] objectAtIndex:0];
[self configureTabBarItemWithImageName:@"home_ON.png" : @"home.png" andText:@"Home" forViewController:controller1];
UIViewController *controller2 = [[tabViewController viewControllers] objectAtIndex:1];
[self configureTabBarItemWithImageName:@"tvChannel_ON.png" : @"tvChannel.png" andText:@"TV" forViewController:controller2];
}
-(void)configureTabBarItemWithImageName:(NSString*)imageName1 : (NSString*)imageName2 andText:(NSString *)itemText forViewController:(UIViewController *)viewController
{
UIImage* icon1 = [UIImage imageNamed:imageName1];
UIImage* icon2 = [UIImage imageNamed:imageName2];
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:itemText image:icon1 tag:0];
[item1 setTitleTextAttributes:@{ UITextAttributeTextColor : [UIColor whiteColor] }
forState:UIControlStateNormal];
[item1 setFinishedSelectedImage:icon1 withFinishedUnselectedImage:icon2];
[viewController setTabBarItem:item1];
}
我在 UINavigationController 中使用 UITabbarcontroller,我无法从 appdelegate 自定义 uitabaritem,如果您运行代码并检查 UITabBarController 中的“初始”,界面显示为真,但是当在 UINavigationController 中检查“初始”时很难这样做