2011-06-13 66 views

回答

1

您可以在這裏找到有關如何創建自定義標籤欄

http://www.rumexit.co.uk/2010/07/how-to-customise-the-tab-bar-uitabbar-in-an-iphone-application-part-1-of-2/

而且你可以按照碼下面的設置圖片&被選擇用於UIControlStateNormal & UIControlStateSelected

UIImage *btnImage = [UIImage imageNamed:@"Button_Normal.png"]; 
UIImage *btnImageSelected = [UIImage imageNamed:@"Bouton_Selected.png"]; 

self.bouton_tab = [UIButton buttonWithType:UIButtonTypeCustom]; //Setup the button 
bouton_tab.frame = CGRectMake(xStart, TABYSTART, TABITEMWIDTH, TABITEMHEIGHT); // Set the frame (size and position) of the button) 
[bouton_tab setBackgroundImage:btnImage forState:UIControlStateNormal]; // Set the image for the normal state of the button 
[bouton_tab setBackgroundImage:btnImageSelected forState:UIControlStateSelected]; // Set the image for the selected state of the button 
[bouton_tab setTag:0]; // Assign the button a "tag" so when our "click" event is called we know which button was pressed. 
[bouton_tab setSelected:true]; // Set this button as selected (we will select the others to false as we only want Tab 1 to be selected initially 

希望,這可以幫助你很多:)

1

你可以使用UITabBarControllerDelegate方法

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    if(tabBarController.selectedIndex==0) 
    { 
     [viewController.tabBarItem setImage:[UIImage imageNamed:@"home.png"]]; 
    } 
} 

使用此代碼在appDelegate.m文件 並添加appDelegate.h一個協議文件

0

您可以自定義標籤欄: 1.創建標籤欄視圖控制器 2。在這個VC把這個方法:

-(void) addCenterButtonWithImage:(UIImage*)buttonImage highlightImage:(UIImage*)highlightImage 
{ 
    self.button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    self.button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin; 
    self.button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height); 
    [self.button setBackgroundImage:buttonImage forState:UIControlStateNormal]; 
    [self.button setBackgroundImage:highlightImage forState:UIControlStateHighlighted]; 

    self.button.center = self.tabBar.center; 

    [self.view addSubview: self.button]; 

} 

在你的標籤欄控制器viewDidLoad調用此方法從這樣:

- (void)viewDidLoad 
{ 
    [self addCenterButtonWithImage:[UIImage imageNamed:@"bemobile.png"] highlightImage:[UIImage imageNamed:@"bemobileSelected.png"]]; 

    [super viewDidLoad]; 
} 

highlightImage傳遞將要顯示的圖像時,選擇該選項卡欄項目

0

我想你需要嘗試這一塊,希望這會有所幫助,

我有改變選擇tabbatitem圖像等 -

中的TabBar控制器委託方法

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 

{ 
    if([tabBarController selectedIndex] == 0) 
    { 
     [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]]; 
    }  
} 

通過這個

你可以改變你的形象。

或者你可以在你的視圖控制器的init(或viewWillAppear中)的方法直接使用,如

 [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];