2011-11-10 10 views
0

ありがとうございます。 2つのタブバーコントローラーを上部に1つ、下部にもう1つ、enter image description here のように追加します。 iPhoneで可能ですか?可能であれば、誰かがこれを行うのを手伝ってください。iphoneのタブバー制御に関連する

+0

カスタマイズ可能なタブバーを使用する必要はありません。 – iOSPawan

答えて

0

私が知る限り、そうすることが可能であるはずです。あなたのビューに1つを追加し、もう1つをrootviewcontrollerに別の位置に追加するだけで、別の場所にリンクすることができます。そうでない場合は、単にPhotoshopをプルアップし、タブバーを「作成」し、その下にボタンを置いて効果をシミュレートします。

PS、サマンサはゴージャス! haha

0

UITabBarはANY方向に変更するのが難しいです。

非常に簡単ですが、あなた自身のカスタムと交換してください。オフコース、それはあなたが好きなことができます。これを見て:

//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に変更することだけです。 UITabBarController * tb = [[CustomTabBar alloc] init];) さらにもう1つ:tabBarのプレゼンテーションがあるので、ビューのサイズが通常どおりに変更されます。このコードを使用すると、それもなりますが、通常のtabBarの場所 - 下部にあります。 2番目のtabBarでは、自分で場所を準備する必要があります。希望、これは役に立ちます。

関連する問題