0

在搜索了如何为我的 iphone 应用程序实现自定义标签栏后,我遇到了位于此处的 TweetBot 标签栏TweetBotTabBar

我下载了 zip 文件并在 Xcode 中打开了 Tweet Bot 项目,但是我不确定如何在我自己的应用程序中使用它。

我是否必须将 TweetBot 项目导入到我自己的项目中,还是必须单独复制和粘贴代码?

我现有的代码使用 SDK 中包含的标准 UITabBarController。

提前感谢您的任何帮助或建议。

4

1 回答 1

0

从源文件中将这些文件复制到您的项目中

标签栏文件

然后创建您的 rootViewController 并向视图添加一个 TBTabBar,将不同的视图控制器分配给您的不同标签栏并在内部实现 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
于 2013-02-02T18:04:35.943 回答