2010-12-09 75 views

回答

0

爲此,您需要創建一個父類爲UITabBar的類。

下面是它的.h文件中:

#import <UIKit/UIKit.h> 


    @interface ImageTabBar : UITabBar 
    { 

    } 

    @end 

這裏是它的.m文件:

#import "ImageTabBar.h" 
    #import "GlobalVars.h" 

    @implementation ImageTabBar 

    - (void) drawRect:(CGRect)rect 
    { 
     UIImage *tabImage; 
     switch (intTabBarSelectedIndex) 
     { 
      case 0: 
       tabImage=[UIImage imageNamed:@"TabBarImageTwitter.png"]; 
       [tabImage drawAtPoint:CGPointMake(0, 0)]; 
       break; 
      case 1: 
       tabImage=[UIImage imageNamed:@"TabBarImageCalender.png"]; 
       [tabImage drawAtPoint:CGPointMake(0, 0)]; 
       break; 

      case 2: 
       tabImage=[UIImage imageNamed:@"TabBarImageStanding.png"]; 
       [tabImage drawAtPoint:CGPointMake(0, 0)]; 
       break; 

      case 3: 
       tabImage=[UIImage imageNamed:@"TabBarImageNews.png"]; 
       [tabImage drawAtPoint:CGPointMake(0, 0)]; 
       break; 

      case 4: 
       tabImage=[UIImage imageNamed:@"TabBarImagePhotos.png"]; 
       [tabImage drawAtPoint:CGPointMake(0, 0)]; 
       break; 

      default: 
       break; 
     } 
    } 

    - (void)dealloc 
    { 
     [super dealloc]; 
    } 


    @end 

在聲明中:

switch (intTabBarSelectedIndex) 

intTabBarSelectedIndex將被定義爲全球變量和整數類型。

現在來到TabBarController類。

這裏是它的.h文件中

#import <UIKit/UIKit.h> 

@class ImageTabBar; 

@interface TabBarViewController : UIViewController <UITabBarControllerDelegate> 
{ 
    ImageTabBar *objOfImageTabBar; 

    IBOutlet UITabBarController *uiTabBarC; 
} 

@property (nonatomic, retain) IBOutlet UITabBarController *uiTabBarC; 

- (void)setNeedsDisplay; 

@end 

這裏是它的.m文件

包括在你的TabBarController類以下功能.m文件:

- (void)viewDidLoad 
{ 
    [self.navigationController setNavigationBarHidden:YES]; 

    self.view    = uiTabBarC.view; 
    uiTabBarC.selectedIndex = intTabBarSelectedIndex; 
    uiTabBarC.delegate  = self; 
    [super viewDidLoad]; 
} 

#pragma mark TaBarViewController delegate 

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    intTabBarSelectedIndex = uiTabBarC.selectedIndex; 

    UITabBar *aTabBar = tabBarController.tabBar; 
    [aTabBar setNeedsDisplay]; 
} 

- (void)setNeedsDisplay 
{ 

} 

做完全像這樣,你的代碼將完美運行。

+0

這個答案需要大量的維修工作。這將在7年內相當難以理解。如果您要呈現多個文件,請不要將它們格式化爲一個代碼塊,並確保您的介入材料被格式化爲普通的段落文本。 – halfer 2018-01-25 21:13:19

相關問題