2012-11-17 100 views
0

我有兩個自定義選項卡欄項目,當它們在特定控制器中被選定時,我想在顏色中突出顯示。但是,當他們沒有被選中時,我希望tabbar顯示我創建的透明標籤欄項目圖像。如何在使用自定義選項卡欄項目時選擇它,並選擇不透明的項目

我試圖在視圖控制器中實現相應的代碼,但它不能正常工作。

[[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:@"tab.png"] `withFinishedUnselectedImage:[UIImage imageNamed:@"transparent.png"]];` 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil方法

什麼我做錯了

回答

0

使用以下方法來定製你的標籤欄:

//UITabBar Customizing Appearance 
{ 
    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabBarBg"]]; 

    int numberOfTabs = 0; 
    numberOfTabs = [[self.tabBarController viewControllers] count]; 

    UIImage *selectionIndicatorImage = [UIImage imageNamed:@"selectionIndicatorImage"]; 
    if (numberOfTabs) { 
     selectionIndicatorImage = [AppDelegate scaleImage:selectionIndicatorImage 
                toSize:CGSizeMake((320.0/numberOfTabs), selectionIndicatorImage.size.height)]; 
    } 

    [[UITabBar appearance] setSelectionIndicatorImage:selectionIndicatorImage];   
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:0.0 green:169.0/255.0 blue:157.0/255.0 alpha:1.0]]; 

    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                 [UIColor colorWithWhite:1.0 alpha:1], UITextAttributeTextColor, 
                 [UIColor lightGrayColor], UITextAttributeTextShadowColor, nil] 
              forState:UIControlStateNormal]; 
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                 [UIColor colorWithWhite:1.0 alpha:1], UITextAttributeTextColor, 
                 [UIColor lightGrayColor], UITextAttributeTextShadowColor, nil] 
              forState:UIControlStateSelected]; 
} 

使用創建的圖像爲選定和未選定標籤items.Also您可以指定標籤數量的圖像。

相關問題