iOS 7 uitabbar shows, invisible on ios8 - ios

I have a previously existing app (pre ios8) that uses UITabbar. The tabbar is visible in ios7 simulator and device, but it is invisible in ios8. What is causing this issue? the space for the tab bar is there, but its background and text/images are not there. i've attached a pic of it.
iOS 7:
iOS 8:

Even if setFinishedSelectedImage:withFinishedUnselectedImage: is deprecated in iOS7, it is working fine in iOS7 but not in 8.
Use image and selectedImage property of UITabBarItem instead.
I also had the same issue but my problem was different.
Reference code:
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
if ([self iOS7OrAbove])
{
//use UIImageRenderingModeAlwaysOriginal to set the custom image for ios 7 and above.
tabBarItem1.selectedImage = [[UIImage imageNamed:#"SelectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem1.image = [[UIImage imageNamed:#"UnselectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
else
{
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"SelectedImage"] withFinishedUnselectedImage:[UIImage imageNamed:#"UnselectedImage"]];
}

Related

TabBar Images not showing in iOS 7.1

I'm developing an app that has iOS 7.1 as its Deployment Target. So far everything works just fine, however there is one huge issue, the tab bar images are not showing up. This is confusing, because they show up when running on the iOS 8 Simulator, I'm using the Xcode 6 beta 1.
I've set up two images. The dimensions are 60x60 and 70x60. So size does not seem to be an issue. I've set the images up in Interface Builder. When logging the tab bar image to the console however, it returns nil. I've then tried setting the images up in code, and using the same method to log it to the console, I now have a memory address for the image, but it still does not show up.
When searching for an answer on Google and stackoverflow, I've found this method:
self.tabBarItem.image = [[UIImage imageNamed:#"IMAGE"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.tabBarItem.selectedImage = [[UIImage imageNamed:#"IMAGE"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
NSLog(#"%#", self.tabBarItem.image);
This worked for some users apparently, but not for me. I can not figure this out, I'd be glad if someone could help me.
I have a feeling about what you're doing, but it's still not clear.
You have a tab bar, but you have an outlet to the tab bar item itself.
That's not the way you would do it. You create an outlet to the tab bar, then add custom items with:
UIImage *defaultImage = [UIImage imageNamed:#"ImageName"];
UIImage *selectedImage = [UIImage imageNamed:#"ImageName"];
UITabBarItem *itemZero = [[UITabBarItem alloc] initWithTitle:#"Item One" image:defaultImage selectedImage:selectedImage];
UITabBarItem *itemOne = [[UITabBarItem alloc] initWithTitle:#"Item Two" image:defaultImage selectedImage:selectedImage];
NSArray *items = #[itemZero,itemOne];
[self.tabBar setItems:items animated:animated];

Trouble showing UITabBarItem.image correct size in iOS 7

I have created a UITabBarcontroller programatically as follows:
UITabBarController *tbc = [[UITabBarController alloc] init];
[tbc setViewControllers:[NSArray arrayWithObjects:vc1,vc2,vc3,vc4,vc5,nil]];
which works ok. For each of the UIViewControllers, i want to set their tabbaritem.image to a specified image so i do this:
UITabBarItem *tbi1 = [[UITabBarItem alloc] initWithTitle:#"Search" image:
[UIImage imageNamed:#"tab_bar_search_50_50.png"] tag:0];
vc1.tabBarItem = tbi1;
and i have also tried
vc1.tabBarItem.image = [UIImage imageNamed:#"tab_bar_search_50_50.png"];
and
UITabBarItem *tbi1 = [[UITabBarItem alloc] initWithTitle:#"Search" image:
[UIImage imageNamed:#"tab_bar_search_50_50.png"] selectedImage:
[UIImage imageNamed:#"tab_bar_search_50_50.png"]];
The image size is 50x50 because according to apple-> https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html#//apple_ref/doc/uid/TP40006556-CH27-SW1
a tabbar icon of size "About 50 x 50 (maximum: 96 x 64) is ok". Yet when i run this in both the simulator and on a device (both retina screens) the image is way too large and hangs over the top of the the tab bar.
Ive even tried adding #2x as a suffix to the file name which doesnt work, but i thought since the app is building only for ios7 that these were no longer needed?
Im guessing the problem is either a bug in iOS7 or the issue lies with the image size, but i read in the documentation that if the image is too big it will be clipped to a certain bound?
I believe i have solved my problem. The problem was that when i added the #2x suffix, i also included this in the naming of the UIImage:
[UIImage imageNamed #"image#2x.png"];
But this needs to be:
[UIImage imageNamed #"image.png"];

UITabBar acts strange in iOS 7, how to fix it?

[[UITabBar appearance] setTintColor:[UIColor redColor]]; // for unselected items that are red
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]]; // for selected items that are green
Why is this code not working in iOS 7?
setTintColor works but only changes the "selected"-icon's color, not the unselected ones as it did in earlier iOS versions, which is weird ? setSelectedImageTintColor does'nt work at all anymore ? Is it realy not possible to color icons as you wish anymore?
Also the setSelectionIndicatorImage is not working as intended in the start of the app, what is happening in iOS 7?
Derp herp Apple, why ?
As of iOS 7 you have to use setBarTintColor: to set the background color, with setTintColor: now affecting the foreground color.
Answer from Adam Waite doesn't work. Method setFinishedSelectedImage under iOS7 ignores the selected image. You need to so it like this:
UITabBarItem *item1 = _tabBarController.tabBar.items[0];
item1.image = [[UIImage imageNamed:#"item1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item1.selectedImage = [UIImage imageNamed:#"item1-selected"];
It's not tint, but you can do it with images:
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:#"item_seleted.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"item_unselected.png"]];
This is a known issue in iOS 7. The tintColor is used for the selected tab image. The selectedImageTintColor is completely ignored. There is no way to tint unselected tab images.
See a discussion on the Apple Developer Forums https://devforums.apple.com/message/851126#851126 about this.
for (int i=0; i (smallerthen)arrayOfTabBarItems.count; i++) {
NSString *unselectedImageName = [NSString stringWithFormat:#"%#.png", arrayOfTabBarItems[i]];
NSString *selectedImageName = [NSString stringWithFormat:#"%#-pressed.png", arrayOfTabBarItems[i]];
[tabBarCtrl.tabBar.items[i] setFinishedSelectedImage:[UIImage imageNamed:selectedImageName] withFinishedUnselectedImage:[UIImage imageNamed:unselectedImageName]];
}
This worked for me.

Setting Image To The UITabbar in iphone?

I am new to ios development.
I created UITabbar programatically and set its delegate to self. All functions well. But my tabbar consists three tab bar items. I have given different images to the different tab bar items. But they all shows another image.
This is my code:
UITabbarItem item1 = [[UITabBarItem alloc] initWithTitle:#"item1" image:[UIImage imageNamed:#"imagename"] tag:1];
Try this :
UIImage *selectedImage0 = [UIImage imageNamed:#"tab-selected.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:#"tab-unselected.png"];
[item1 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];

Setting the height of UITabBar

I've created a simple custom tabbar by setting the images of each item, as following:
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
[item0 setFinishedSelectedImage:[UIImage imageNamed:#"activity_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"activity.png"]];
[item1 setFinishedSelectedImage:[UIImage imageNamed:#"agenda_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"agenda.png"]];
[item2 setFinishedSelectedImage:[UIImage imageNamed:#"settings_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"settings.png"]];
While this works great, I noticed that there is a black blank space under my tabbar
My images are 44px in height, but I think I have to somehow change the height of my tabbar.
The tabBar itself is 49px, and it is rendered in black color behind your images (perhaps in [UITabBar layoutSubviews]). Then your images are rendered on top. The reason of the offset is because the images you supply are too large, UITabBar expects 30x30px icons, not a picture of the entire UITabBarItem.
Here's a few things to try:
Supply only a 30x30px icon, instead of the entire tab button
After you set your images on the tab item, try this:
[item setImageInsets:UIEdgeInsetsMake(6, 0, -6, 0)]; // play with insets until it renders correctly
Subclass UITabBar and override layoutSubviews to first call super, then reposition your image as you like. Not recommended, it might break in future iOS versions.
Use -
tabBar.frame=CGRectMake(x,y,w,h);
In this way you can set xCord, yCord, width and height.
Check this:
[self.tabBar setFrame:CGRectMake(self.tabBar.frame.origin.x, self.tabBar.frame.origin.y - 30, self.tabBar.frame.size.width, self.tabBar.frame.size.height + 30)];

Resources