Search code examples
iosxcoderesolution

UITabBar only shows Black/Blue Square Place holder like image, what could be a potential reason?


I am now adapting @1x, @2x, @3x for different iPhone screens sizes. And this problem come to puzzle me:

Code I'm using:

UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Home" image:[UIImage imageNamed:@"tabbar_circle"]  selectedImage:[UIImage imageNamed:@"tabbar_circle_blue"]];
_circleNavController.tabBarItem = item;

Instead showing some images that make sense, it only shows a placeholder with blue/black square, I am sure the image names are correct since a wrong name will return to an empty area.

Blue Square Placeholder


Solution

  • UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Home" image:[[UIImage imageNamed:@"tabbar_circle"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                                       selectedImage:[[UIImage imageNamed:@"tabbar_circle_blue"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                  ];
    

    Finally got this solution, enlighten by @matt