UITabBar not showing selected item images in ios 7

后端 未结 20 1880
我在风中等你
我在风中等你 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:12

    You need to use tabBarItem initWithTitle:image:selectedImage

    [[UITabBarItem alloc] initWithTitle:@"title" image:image selectedImage:imageSel];
    

    in conjunction with changing the UIImage rendering mode:

    imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal
    

    or (to apply parent views template tint mask, this option is default for Tab bar Items unless you opt out with the above rendering mode)

    imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate
    

    here is a code sample for one tab bar item :-

    UIImage *musicImage = [UIImage imageNamed:@"music.png"];
    UIImage *musicImageSel = [UIImage imageNamed:@"musicSel.png"];
    
    musicImage = [musicImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    musicImageSel = [musicImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.musicViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Music" image:musicImage selectedImage:musicImageSel];
    

    Hope this helps

提交回复
热议问题