Icons displaying in selected state in more tabbar controller IOS8 - ios

I am using a tab bar controller in my app, and I have more tab bar view controllers. In iOS 8 icons that are assigned to tabs in more tab bar are always in selected(Blue) state, which worked fine in iOS7?
image = [UIImage imageWithContentsOfFile:imagePath];
UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:tag];

you can try with following code:
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
[tabBarItem1 setImage:[[UIImage imageNamed:#"tab1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:#"tab1Selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setTitle:title];
and you can do the same things with other tabs

Related

NSRangeException indexOutOfBound

I am using code that I made in another application. In the other application the code is working fine. What I do is while loading splashViewController the images of slideShow are being downloaded and cached. When the download is finished it will present the mainviewcontroller which is a maintableviewcontroller. Here is the code that I am using:
UIImage* tabBarBackground = [UIImage imageNamed:#"tabBar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
UITabBarController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"barController"];
UITabBar *tabBar = rootViewController.tabBar;
UITabBarItem *tabBarItem1 = tabBar.items[0];// the error here happening event if i comment out this line the error is hapen at the next uibar items
UIImage *selectedLogo = [[UIImage imageNamed:#"productSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *unselectedLogo = [[UIImage imageNamed:#"product"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[tabBarItem1 setImage:unselectedLogo];
[tabBarItem1 setSelectedImage:selectedLogo];
[tabBarItem1 setTitle:#"My Product"];
UITabBarItem *tabBarItem2 = tabBar.items[1];
UIImage *selectednews = [[UIImage imageNamed:#"notificationSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *unselectednews = [[UIImage imageNamed:#"notification"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[tabBarItem2 setImage:unselectednews];
[tabBarItem2 setSelectedImage:selectednews];
[tabBarItem2 setTitle:#"Notifications"];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
UIImage *selectedLocation = [[UIImage imageNamed:#"locationSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *unselectedLocation = [[UIImage imageNamed:#"location"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[tabBarItem3 setImage:unselectedLocation];
[tabBarItem3 setSelectedImage:selectedLocation];
[tabBarItem3 setTitle:#"Locate Us"];
UITabBarItem *tabBarItem4 = tabBar.items[3];
UIImage *selectedaboutus = [[UIImage imageNamed:#"moreSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *unselectedaboutus = [[UIImage imageNamed:#"more"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[tabBarItem4 setImage:unselectedaboutus];
[tabBarItem4 setSelectedImage:selectedaboutus];
[tabBarItem4 setTitle:#"More"];
[self.loadingActivityIndicator stopAnimating];
[self.navigationController popToRootViewControllerAnimated:YES];
[self presentViewController:rootViewController animated:YES completion:nil];
Please put a count check for tabbar.items first and then access all tab bar items :
if(tabbar.items.count==tabCount) //tabCount is number of tabs in your tabbar
{
UITabBarItem *tabBarItem1 = tabBar.items[0];
//<remaining code>
}else
{
//either tabbar is nil or tabbar doesn't not have any tabs, so handle accordingly
}
Also, since the tabbar is working fine in another application, please check your StoryBoard if it correctly creates and binds the tabbar for the rootViewController.
Here is a good post with detailed steps to create tabbar correctly using Storyboards which can help you debug/verify if you created the bindings and segues correctly:
https://guides.codepath.com/ios/Using-Tab-Bar-Controllers

Setting TabBar Item title and Image on Selection in XCode 6.4

I am using xcode 6.4 and using storyboard to set up Tab bar controller Item and its Images.
Issue 1- In storyboard on tab bar item selection, there are already option for Bar Item and Image selection. i have assigned Images on both field but Images are not changing at time of selection.Only default(black) image exists.
I have referred to this Link . Then also default (black) exists
Issue 2- In storyboard i have assigned all images on Bar Item and Image Selection and used given code then title is not visible in tab bar item. only image is working fine on selection.
Code-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Assign tab bar item with titles
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
UITabBarItem *tabBarItem5 = [tabBar.items objectAtIndex:4];
tabBarItem1.title = #"Home";
tabBarItem2.title = #"Search";
tabBarItem3.title = #"Cart";
tabBarItem4.title = #"Account";
tabBarItem5.title = #"More";
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:#"HomeSelected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem2 setSelectedImage:[[UIImage imageNamed:#"SearchOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem3 setSelectedImage:[[UIImage imageNamed:#"CartOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem4 setSelectedImage:[[UIImage imageNamed:#"ProfileOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem5 setSelectedImage:[[UIImage imageNamed:#"MoreTabOpened.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
// Change the tab bar background
UIImage* tabBarBackground = [UIImage imageNamed:#"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"tabbar_selected.png"]];
// Change the title color of tab bar items
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], NSForegroundColorAttributeName,
nil] forState:UIControlStateNormal];
UIColor *titleHighlightedColor = [UIColor colorWithRed:255.0/255.0 green:109.0/255.0 blue:0.0/255.0 alpha:1.0];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
titleHighlightedColor, NSForegroundColorAttributeName,
nil] forState:UIControlStateHighlighted];
return YES;
}
I've seen gone through iOS Docs, but could not find any useful update on these issues. please update me on it.
You should create your custom tabbar
Useful link : http://swiftiostutorials.com/tutorial-custom-tabbar-storyboard/

How to change grey color of icons in "more" uitableview on ios 7?

In ios 7 if you have more than 4 items in uitabbar, the other will be put in a "more" table view. How do I change the color of the icon in that view? I use this code to set icons in my appdelegate.m, but they appear greyed as in photo.
UITabBarItem *tabBarItem;
UIImage *unselectedImage;
UIImage *selectedImage;
tabBarItem = [tabBarController.tabBar.items objectAtIndex:4];
unselectedImage = [UIImage imageNamed:#"photo.png"];
selectedImage = [UIImage imageNamed:#"another_photo.png"];
[tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem setSelectedImage: [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
Set the global tint color of your app:
[self.window setTintColor:[UIColor XXXX]];

How to set the images for UITabBarItems without having titles?

I had an application in which I am adding the images for the UITabBarItems programatically like this..
UIImage *selectedImage0 = [UIImage imageNamed:#"home_hvr.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:#"home.png"];
UIImage *selectedImage1 = [UIImage imageNamed:#"star_hvr.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:#"star.png"];
UITabBar *tabBar = self.tabbarcontroller.tabBar;
self.tabbarcontroller.tabBar.barStyle = UIBarStyleBlack;
self.tabbarcontroller.tabBar.translucent = NO;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
[item0 setSelectedImage:[selectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item0 setImage:[unselectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item1 setSelectedImage:[selectedImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item1 setImage:[unselectedImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
since the tabbaritems doesn't have any titles it will bring a blank space at the bottom of the tab-bar pulling the image above the tab bar,I need no titles but needs to put my image inside the tab bar completely.
Can any body guide me on this?
UITabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
was done this trick worked for me .thanks
Try below code:
[[self.tabBarController.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:#"offer_btn_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"offer_btn.png"]];
[[self.tabBarController.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:#"merchant_btn_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"merchant_btn.png"]];

Remove line on custom tab bar

I made a custom tab bar with one of them extending beyond the bar. There is a line overlapping the center tab bar. Is there anyway I can get rid or this or hide it?
To do it, I just set tab bar images:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
tabBarItem3.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"scheduleTabBarImageSel.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"scheduleTabBarImage.png"]];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:#"favoritesTabBarImageSel.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"favoritesTabBarImage.png"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:#"searchTabBarImageSel.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"searchTabBarImage.png"]];
Any idea how to hide the line? Thanks
If I'm understanding your correctly, the problem is with the 1-2ish pixel shadow sitting on top of the tab bar. If this is the case, you can remove the shadow the same way you would with a navigation bar. Simply enable clips to bounds.
[self.tabBarController.tabBar setClipsToBounds:YES];
This seemed to work for me:
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];

Resources