简体   繁体   English

iPhone SDK:自定义选项卡栏-如何使用TweetBotTabBar

[英]iPhone SDK: Custom Tab Bar - How to use TweetBotTabBar

After searching on how to implement a custom tab bar for my iphone app, I came across the TweetBot Tab Bar located here TweetBotTabBar 关于如何实现我的iPhone应用程序的自定义标签栏搜索后,我遇到了位于这里的TweetBot标签栏TweetBotTabBar

I downloaded the zip file and opened the Tweet Bot project in Xcode, however i'm not sure how to go about using it in my own app. 我下载了zip文件并在Xcode中打开了Tweet Bot项目,但是我不确定如何在自己的应用程序中使用它。

Do I have to import the TweetBot project into my own project or do I have to copy and paste the code separately? 我是否必须将TweetBot项目导入到我自己的项目中,还是必须分别复制和粘贴代码?

My existing code uses the standard UITabBarController included in the SDK. 我现有的代码使用SDK中包含的标准UITabBarController。

Thanks in advance for any help or suggestions. 在此先感谢您的帮助或建议。

From the source file copy these files into your project 从源文件中将这些文件复制到您的项目中

标签栏文件

Then create your rootViewController and add a TBTabBar to the view, assign different viewcontroller to your different tabbars and implement TBTabbarDelegate inside. 然后创建您的rootViewController并向视图添加一个TBTabBar,为不同的选项卡栏分配不同的viewcontroller,并在其中实现TBTabbarDelegate。

#import <UIKit/UIKit.h>
#import "TBTabBar.h"
@interface ViewController : UIViewController<TBTabBarDelegate>{
    TBTabBar *tabBar;
}

@end

Implementation of this view controller will be as follow 该视图控制器的实现如下

#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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM