提前致谢。 我想添加两个tabbar控制器,一个在顶部,另一个在底部,如 这个。它是否可能在iPhone上。如果可能,任何人都知道请帮助我这样做。
答案 0 :(得分:0)
据我所知,应该可以这样做。只需在视图中添加一个,将另一个添加到rootviewcontroller,在不同的位置,您应该能够链接到不同的位置。如果没有,只需拉起photoshop,“制作”标签栏并在其下面放置按钮以模拟效果。
PS,萨曼莎很华丽!哈哈答案 1 :(得分:0)
UITabBar很难在任何方向上进行修改。
很多easyer将用您自己的自定义替换它。 Offcorse,它可以是你喜欢的任何东西。看看这个:
//CustomTabBar.h:
#import <Foundation/Foundation.h>
@interface CustomTabBar : UITabBarController {
UIButton *SHOPPING;
UIButton *DINING;
UIButton *MAPS;
UIButton *PARKING;
UIButton *PROMOTION;
UIImageView *BarBackground;
}
-(void) addCustomElements;
-(void) hideExistingTabBar;
-(void) selectTab:(int)tabID;
@end
//CustomTabBar.m:
#import "CustomTabBar.h"
@implementation CustomTabBar
- (void)viewDidAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self hideExistingTabBar];
[self addCustomElements];
}
- (void)hideExistingTabBar
{
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
view.hidden = YES;
break;
}
}
}
- (void)dealloc {
[super dealloc];
}
-(void)addCustomElements
{
//in your case you will need 2 bars, but I needed only one. Just add another one.
BarBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BarBackground.jpg"]];
BarBackground.frame = CGRectMake(0, 430, 320, 50);
// Initialise our two images
UIImage *btnImage = [UIImage imageNamed:@"BarShipping.png"];
UIImage *btnImageSelected = [UIImage imageNamed:@"BarShipping.png"];
SHOPPING = [UIButton buttonWithType:UIButtonTypeCustom]; //Setup the button
SHOPPING.frame = CGRectMake(0, 430, 64, 50); // Set the frame (size and position) of the button)
[SHOPPING setBackgroundImage:btnImage forState:UIControlStateNormal]; // Set the image for the normal state of the button
[SHOPPING setBackgroundImage:btnImageSelected forState:UIControlStateSelected]; // Set the image for the selected state of the button
[SHOPPING setTag:0]; // Assign the button a "tag" so when our "click" event is called we know which button was pressed.
[SHOPPING setSelected:true]; // Set this button as selected (we will select the others to false as we only want Tab 1 to be selected initially
// Now we repeat the process for the other buttons
btnImage = [UIImage imageNamed:@"BarDinning.png"];
btnImageSelected = [UIImage imageNamed:@"BarDinning.png"];
DINING = [UIButton buttonWithType:UIButtonTypeCustom];
DINING.frame = CGRectMake(64, 430, 64, 50);
[DINING setBackgroundImage:btnImage forState:UIControlStateNormal];
[DINING setBackgroundImage:btnImageSelected forState:UIControlStateSelected];
[DINING setTag:1];
<...>
// Add my new buttons to the view
[self.view addSubview:BarBackground];
[self.view addSubview:SHOPPING];
[self.view addSubview:DINING];
<...>
// Setup event handlers so that the buttonClicked method will respond to the touch up inside event.
[SHOPPING addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[DINING addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
<...>
}
- (void)selectTab:(int)tabID
{
//if you will need navigation controller, or something, you will need to work on this part, or it will just crash.
switch(tabID)
{
case 0:
[SHOPPING setSelected:true];
[DINING setSelected:false];
<...>
break;
case 1:
[SHOPPING setSelected:false];
[DINING setSelected:true];
<...>
break;
<...>
}
if (self.selectedIndex == tabID) {
UINavigationController *navController = (UINavigationController *)[self selectedViewController];
[navController popToRootViewControllerAnimated:YES];
} else {
self.selectedIndex = tabID;
}
}
- (void)buttonClicked:(id)sender
{
int tagNum = [sender tag];
[self selectTab:tagNum];
}
@end
然后,像往常一样添加和使用TabBarController。你唯一要做的就是将TabBarController的类改为你的xib文件中的CastomTabBar。 (或者使用此类分配它,如果你在programmaticaly中添加它:UITabBarController * tb = [[CustomTabBar alloc] init];) 还有一件事:有一个地方,为tabBar提供,所以你的视图通常会重新调整大小。如果您使用此代码,它也会使用,但在通常的tabBar位置 - 在底部。对于第二个tabBar,您需要自己准备好位置。希望,这会有所帮助。