okay, i have found the solution to this, by far i've tried both customized tabbar and segmented controller, but i found both of them risky and too complicated
so i do a little experiment with simple button
here's the main idea
first, i set up a toolbar, and give it a background
-in viewController.h
//adding my viewcontrollers
@class notLoggedHome;
@class LoggedInHome;
@class NABViewController;
//defining all the objects
@properties (nonatomic, strong) UIToolBar *mainToolBar;
@properties (nonatomic, strong) UIButton *toolBarBut1, *toolBarBut2, *toolBarBut3;
@properties (nonatomic, strong) UIImageView *logoImage;
@property (nonatomic, strong) notLoggedHome *viewNotLoggedHome;
@property (nonatomic, strong) LoggedInHome *viewLoggedInHome;
@property (nonatomic, strong) NABViewController *viewNAB;
@properties NSInteger lastTag;
-in viewController.m
@synthesize mainToolBar, toolBarBut1, toolBarBut2, toolBarBut3;
@synthesize logoImage, lastTag;
@synthesize viewNotLoggedHome, viewLoggedInHome, viewNAB;
-(void)viewDidLoad
{
lastTag = 100;
self.view.backgroundColor = [UIColor colorWithRed:21.0/255.0 green:21.0/255.0 blue:21.0/255.0 alpha:1];
//---
//---fakeTabBar set up===
viewNotLoggedHome = [[notLoggedHome alloc]init];
viewLoggedInHome = [[LoggedInHome alloc]init];
viewNAB = [[NABViewController alloc]init];
//creating the fakeTabBar
mainToolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)];
[mainToolBar setBackgroundImage:[UIImage imageNamed:@"menu_bar.jpg"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
//defining images
imgHome = [UIImage imageNamed:@"menu_home.png"];
imgHomeS = [UIImage imageNamed:@"menu_home_s.png"];
imgLogo = [UIImage imageNamed:@"menu_bar_logo_ep.png"];
UIImageView *logoImage = [[UIImageView alloc]initWithImage:imgLogo];
logoImage.frame = CGRectMake(0, 0, imgLogo.size.width, imgLogo.size.height);
//--button setting====
toolBarBut1 = [UIButton buttonWithType:UIButtonTypeInfoLight];
[toolBarBut1 setFrame:CGRectMake(imgLogo.size.width, 1, imgHome.size.width, imgHome.size.height)];
toolBarBut1.tag = 0;
toolBarBut1.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
[toolBarBut1 setImage:imgHome forState:UIControlStateNormal];
[toolBarBut1 setImage:imgHomeS forState:UIControlStateSelected];
[toolBarBut1 addTarget:self action:@selector(barPressed:) forControlEvents:UIControlEventTouchUpInside];
//do the same with the other 2 button
//---------------------
[mainToolBar addSubview:logoImage];
[mainToolBar addSubview:toolBarBut1];
//do the same with the other 2 button
[self.view addSubview:mainToolBar];
[super viewDidLoad];
}
-(void)barPressed:(id)sender
{
UIButton *button = (UIButton *)sender;
if(button.tag == 0 && button.tag != lastTag)
{
[viewNAB removeFromParentViewController];
[viewNotLoggedHome removeFromParentViewController];
[self.view addSubview:viewLoggedInHome.view];
button.selected = YES;
}
if(button.tag == 1 && button.tag != lastTag)
{
[viewNAB removeFromParentViewController];
[viewLoggedInHome removeFromParentViewController];
[self.view addSubview:viewNotLoggedHome.view];
button.selected = YES;
}
if(button.tag == 2 && button.tag != lastTag)
{
[viewLoggedInHome removeFromParentViewController];
[viewNotLoggedHome removeFromParentViewController];
[self.view addSubview:viewLoggedInHome.view];
button.selected = YES;
}
lastTag = button.tag;
}
so the main idea is creating a fake tabbar by using toolbar, assigning UIButton(s) to the toolbar as the fake tabbaritem, and giving mechanism to each button that later will switch your viewcontrollers (you have to alloc the viewcontrollers first at implementation file)
this works well for me, just dont forget to set the view controllers frame Y point +(toolbar Height) because otherwise it will cover the toolbar later
:)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…