2012-10-09 170 views
0

我的應用程序包含標籤欄和狀態欄。標籤欄的結構與具有背景圖像的按鈕相似,並將這些按鈕添加到TabBar上。問題是,按鈕的高度爲47,但我們的默認Tabar高度爲49.因此,Tabbar和視圖之間會出現間隙。在xib中,我試圖改變視圖的框架大小。但這是不可能的。通過defualt它來了411.我怎樣才能解決這個問題?有沒有什麼辦法可以創建一個自定義的標籤欄?自定義標籤欄問題

這裏是我的TabBar

viewController1 *viewController1Obj = [[viewController1 alloc] initWithNibName:@"viewController1" bundle:nil]; 
viewController2 *viewController2Obj = [[viewController2 alloc] initWithNibName:@"viewController2" bundle:nil]; 

viewController3 *viewController3Obj = [[viewController3 alloc] initWithNibName:@"viewController3" bundle:nil]; 
viewController4 *viewController4Obj = [[viewController4 alloc] initWithNibName:@"viewController4" bundle:nil]; 
viewController5 *viewController5Obj = [[viewController5 alloc] initWithNibName:@"viewController5" bundle:nil]; 

UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:viewController1Obj]; 
UINavigationController *nav2=[[UINavigationController alloc]initWithRootViewController:viewController2Obj]; 
UINavigationController *nav3=[[UINavigationController alloc]initWithRootViewController:viewController3Obj]; 
UINavigationController *nav4=[[UINavigationController alloc]initWithRootViewController:viewController4Obj]; 
UINavigationController *nav5=[[UINavigationController alloc]initWithRootViewController:viewController5Obj]; 

nav1.navigationBarHidden=YES; 
nav2.navigationBarHidden=YES; 
nav3.navigationBarHidden=YES; 
nav4.navigationBarHidden=YES; 
nav5.navigationBarHidden=YES; 

self.tabBarController = [[UITabBarController alloc] init]; 

self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1, nav2,nav3,nav4 ,nav5, nil]; 

self.tabBarController.tabBar.frame = CGRectMake(0.0f, self.tabBarController.tabBar.frame.origin.y, 320.0f, 47.0f); 

[self.window addSubview:self.tabBarController.view]; 

self.tabBarController.view.backgroundColor = [UIColor redColor]; 


self.tabBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 64.0f, 47.0f)]; 
[self.tabBtn1 setImage:[UIImage imageNamed:@"button1.png"] forState:0]; 
[self.tabBtn1 setTag:77777]; 
self.tabBtn1.adjustsImageWhenHighlighted = NO; 
[self.tabBtn1 addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside]; 

self.tabBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(64.0f, 0.0f, 64.0f, 47.0f)]; 
[self.tabBtn2 setImage:[UIImage imageNamed:@"button2.png"] forState:0]; 
[self.tabBtn2 setTag:77778]; 
self.tabBtn2.adjustsImageWhenHighlighted = NO; 
[self.tabBtn2 addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside]; 

self.tabBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(128.0f, 0.0f, 64.0f, 47.0f)]; 
[self.tabBtn3 setImage:[UIImage imageNamed:@"button3.png"] forState:0]; 
[self.tabBtn3 setTag:77779]; 
self.tabBtn3.adjustsImageWhenHighlighted = NO; 
[self.tabBtn3 addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside]; 

self.tabBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(192.0f, 0.0f, 64.0f, 47.0f)]; 
[self.tabBtn4 setImage:[UIImage imageNamed:@"button4.png"] forState:0]; 
[self.tabBtn4 setTag:77780]; 
self.tabBtn4.adjustsImageWhenHighlighted = NO; 
[self.tabBtn4 addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside]; 

self.tabBtn5 = [[UIButton alloc] initWithFrame:CGRectMake(256.0f, 0.0f, 64.0f, 47.0f)]; 
[self.tabBtn5 setImage:[UIImage imageNamed:@"button5.png"] forState:0]; 
[self.tabBtn5 setTag:77781]; 
self.tabBtn5.adjustsImageWhenHighlighted = NO; 
[self.tabBtn5 addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside]; 

[self.tabBarController.tabBar addSubview:self.tabBtn1]; 
[self.tabBarController.tabBar addSubview:self.tabBtn2]; 
[self.tabBarController.tabBar addSubview:self.tabBtn3]; 
[self.tabBarController.tabBar addSubview:self.tabBtn4]; 
[self.tabBarController.tabBar addSubview:self.tabBtn5]; 

,並在其蔭得到的是呈現紅色的差距代碼。

+0

請分享您的代碼:) – 2012-10-09 07:03:02

回答

0

我解決了這個問題UITabbarController子視爲

[[[self.tabBarController.view subviews]objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 521)]; 

現在差​​距已經消失。