UITabBar not showing selected item images in ios 7

后端 未结 20 1843
我在风中等你
我在风中等你 2020-11-29 18:36

The icons show fine in ios 6 but not in ios 7. I\'m setting the selected state in the viewController viewDidLoad method. When the user selects a tab bar item the image disap

20条回答
  •  死守一世寂寞
    2020-11-29 19:09

    It is easy and clean solution of category for UITabBar Items.

    Just create category and use the Runtime Attribute and refer it from category like below. Add Runtime Attribute for selected TabBarItem Refer it from category and make changes

    #import "UITabBarItem+CustomTabBar.h"
    
    @implementation UITabBarItem (CustomTabBar)
    
    -(void)setValue:(id)value forKey:(NSString *)key {
        if([key isEqualToString:@"tabtitle"]){
            if([value isEqualToString:@"contacts"]) {
                [self setSelectedImage:[[UIImage imageNamed:@"contacts-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
            } else if([value isEqualToString:@"chat"]) {
                [self setSelectedImage:[[UIImage imageNamed:@"chat-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
            } else if([value isEqualToString:@"groupchat"]) {
                [self setSelectedImage:[[UIImage imageNamed:@"groupchat-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
            } else if([value isEqualToString:@"settings"]) {
                [self setSelectedImage:[[UIImage imageNamed:@"settings-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
            }
        }
        [self setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Roboto-Regular" size:12.0f], NSFontAttributeName, [UIColor grayColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    }
    
    @end
    

提交回复
热议问题