【问题标题】:How can i use custom tab bar item when it's selected and a transparent one it's not selected我如何在选择时使用自定义标签栏项目而未选择透明的标签栏项目
【发布时间】:2012-11-06 05:56:23
【问题描述】:

我有两个自定义标签栏项目,当它们在某个控制器中被选中时,我希望它们以颜色突出显示。但是,当它们未被选中时,我希望标签栏显示我创建的透明标签栏项目图像。

我尝试在视图控制器中实现相应的代码,但它无法正常工作。

[[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:@"tab.png"] `withFinishedUnselectedImage:[UIImage imageNamed:@"transparent.png"]];`

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil方法中

我做错了什么?

【问题讨论】:

    标签: iphone ios5 uitabbarcontroller tabbar uitabbaritem


    【解决方案1】:

    使用以下内容自定义标签栏:

    //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];
    }
    

    使用创建的图像作为选定和未选定选项卡项的图像。您也可以指定选项卡的数量。

    【讨论】:

      猜你喜欢
      • 2017-04-08
      • 2011-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多