我想为我的应用程序制作一个自定义tabbar,我已经尝试将我的代码放在第一个viewcontroller中,它可以工作! 但这是问题所在,我想声明并将我的代码放在Appdelegate.m中,但是当我运行它时,它只显示一个没有图像的黑色tabbar控制器。 为了您的信息,我从故事板中嵌入我的tabbar控制器。
这是代码
UIImage *selectedImage0 = [UIImage imageNamed:@"img1.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"img1hov.png"];
UIImage *selectedImage1 = [UIImage imageNamed:@"img2.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"img2hov.png"];
UIImage *selectedImage2 = [UIImage imageNamed:@"img3.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"img3hov.png"];
UIImage *selectedImage3 = [UIImage imageNamed:@"img4.png"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"img4hov.png"];
UIImage *selectedImage4 = [UIImage imageNamed:@"img5.png"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"img5hov.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
UITabBarItem *item4 = [tabBar.items objectAtIndex:4];
tabBar.backgroundImage = [UIImage imageNamed:@"back_menu.png"];
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];
答案 0 :(得分:1)
通过以下链接, 1)http://idevrecipes.com/2011/01/04/how-does-the-twitter-iphone-app-implement-a-custom-tab-bar/
2)http://www.simplecode.me/2011/12/05/tab-based-ios-apps-uitabbarcontroller/
3)http://sugartin.info/2011/07/01/customizing-tab-bar/
4)http://code4app.net/ios/TabBar-with-Expands/5004e0206803fa546a000001
答案 1 :(得分:0)
该代码对我来说很好。如何在appDelegate中将UIViewController
添加到UITabBarController
?不是这样的吗?
//appDelegate.h
@property (nonatomic, strong) SomeViewController *viewController;
@property (nonatomic, strong) UITabBarController *tabBarController;
//and synthesize those
//appDelegate.m
self.viewController = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:nil];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[NSArray arrayWithObjects:self.viewController, nil];
您可以使用self.tabBarController
self.viewController
和((AppDelegate *)[UIApplication sharedApplication].delegate)