在搜索了如何为我的iphone应用程序实现自定义标签栏后,我遇到了位于此处的TweetBot标签栏TweetBotTabBar
我下载了zip文件并在Xcode中打开了Tweet Bot项目,但是我不知道如何在我自己的应用程序中使用它。
我是否必须将TweetBot项目导入我自己的项目中,还是必须单独复制和粘贴代码?
我现有的代码使用SDK中包含的标准UITabBarController。
提前感谢您的任何帮助或建议。
答案 0 :(得分:0)
从源文件中将这些文件复制到项目中
然后创建rootViewController并将TBTabBar添加到视图中,将不同的viewcontroller分配给不同的tabbars并在其中实现TBTabbarDelegate。
#import <UIKit/UIKit.h>
#import "TBTabBar.h"
@interface ViewController : UIViewController<TBTabBarDelegate>{
TBTabBar *tabBar;
}
@end
此视图控制器的实现如下
#import "ViewController.h"
#import "TweetBotTabBarTestViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)dealloc
{
[tabBar release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
TweetBotTabBarTestViewController *vc1 = [[TweetBotTabBarTestViewController alloc] init];
TweetBotTabBarTestViewController *vc2 = [[TweetBotTabBarTestViewController alloc] init];
TBViewController *vc3 = [[TBViewController alloc] init];
vc3.view.backgroundColor = [UIColor darkGrayColor];
TBTabButton *t1 = [[[TBTabButton alloc] initWithIcon:[UIImage imageNamed:@"timelineIcon"]] autorelease];
t1.highlightedIcon = [UIImage imageNamed:@"timelineIconHighlighted"];
t1.viewController = vc1;
TBTabButton *t2 = [[[TBTabButton alloc] initWithIcon:[UIImage imageNamed:@"mentionsIcon"]] autorelease];
t2.highlightedIcon = [UIImage imageNamed:@"mentionsIconHighlighted"];
t2.viewController = vc2;
TBTabButton *t3 = [[[TBTabButton alloc] initWithIcon:[UIImage imageNamed:@"messagesIcon"]] autorelease];
t3.highlightedIcon = [UIImage imageNamed:@"messagesIconHighlighted"];
t3.viewController = vc3;
TBTabButton *t4 = [[[TBTabButton alloc] initWithIcon:[UIImage imageNamed:@"favoritesIcon"]] autorelease];
t4.highlightedIcon = [UIImage imageNamed:@"favoritesIconHighlighted"];
t4.viewController = vc3;
TBTabButton *t5 = [[[TBTabButton alloc] initWithIcon:[UIImage imageNamed:@"searchIcon"]] autorelease];
t5.highlightedIcon = [UIImage imageNamed:@"searchIconHighlighted"];
t5.viewController = vc3;
NSArray *a = [NSArray arrayWithObjects:t1, t2, t3, t4, t5, nil];
tabBar = [[TBTabBar alloc] initWithItems:a];
tabBar.delegate = self;
[self.view addSubview:tabBar];
[tabBar showDefaults];
}
#pragma mark - TBTabbar Delegate
-(void)switchViewController:(UIViewController *)viewController {
UIView *currentView = [self.view viewWithTag:SELECTED_VIEW_CONTROLLER_TAG];
[currentView removeFromSuperview];
viewController.view.frame = CGRectMake(0,0,self.view.bounds.size.width, self.view.bounds.size.height-(tabBar.frame.size.height));
viewController.view.tag = SELECTED_VIEW_CONTROLLER_TAG;
[self.view insertSubview:viewController.view belowSubview:tabBar];
}
@end