Remove line on custom tab bar - ios

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]];

Related

Tabbar item images not loaded first time

i am using tabbarcontroller in my project. Here is my storyboard
In all view controllers tabbar item, I set images like below
I make a class of tabbarcontroller and do coding below
UITabBar *tabBar = self.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 setImage:[[UIImage imageNamed:#"ic_home_tab_home_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
// [tabBarItem1 setSelectedImage:[[UIImage imageNamed:#"ic_home_tab_home_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"ic_home_tab_home_sel"] withFinishedUnselectedImage:[UIImage imageNamed:#"ic_home_tab_home"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:#"ic_home_tab_profile_sel"] withFinishedUnselectedImage:[UIImage imageNamed:#"ic_home_tab_profile"]];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:#"ic_home_create_post_sel"] withFinishedUnselectedImage:[UIImage imageNamed:#"ic_home_create_post"]];
[tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:#"ic_home_tab_chat_sel"] withFinishedUnselectedImage:[UIImage imageNamed:#"ic_home_tab_chat"]];
[tabBarItem5 setFinishedSelectedImage:[UIImage imageNamed:#"ic_home_tab_setting_sel"] withFinishedUnselectedImage:[UIImage imageNamed:#"ic_home_tab_setting"]];
But When I run it, First time all images are mixed, But when I clicked them one by one like in Video then all images sets.I dont know why this happend? Please help meThank you
I also faced same problem then I used below code in appdelegate
UINavigationController *navigationVC1 = [[UINavigationController alloc]initWithRootViewController:viewController1];
navigationVC1.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"My Trips"
image:[UIImage imageNamed:#"cab.png"]
tag:1];
UINavigationController *navigationVC2 = [[UINavigationController alloc]initWithRootViewController:viewController2];
navigationVC2.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"My Children"
image:[UIImage imageNamed:#"kids-couple.png"]
tag:2];
try like this.

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/

Icons displaying in selected state in more tabbar controller IOS8

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

UITabBar custom icon color is not getting shown

I am using UITabBar in iOS app. I have set images to UITabBar items. Code is-
self.mainTabBar.delegate = self;
mainTabBar.tintColor = nil;
[[mainTabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:#"ic_1.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"ic_1.png"]];
[[mainTabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:#"ic_2.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"ic_2.png"]];
[[mainTabBar.items objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:#"ic_3.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"ic_3.png"]];
[[mainTabBar.items objectAtIndex:3] setFinishedSelectedImage:[UIImage imageNamed:#"ic_4.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"ic_4.png"]];
[[mainTabBar.items objectAtIndex:4] setFinishedSelectedImage:[UIImage imageNamed:#"ic_5.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"ic_5.png"]];
This is code for tab bar. It is showing like -
Actual icon image is like (colors are like this)-
How can I show actual colors of icon?
You can use it like this if you are using iOS 8.
UIImage *image1 = [[UIImage imageNamed:#"message"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem1.image = image1;
tabBarItem1.selectedImage = image11;
Here is the source : UITabBarItem/selectedImage
By default, the actual selected image is automatically created from
the alpha values in the source image. To prevent system coloring,
provide images with UIImageRenderingModeAlwaysOriginal.
Set the UITabBarItems from inside their view controllers. Do not set them directly.
For example:
UITableViewController *searchTableCon = [[UITableViewController alloc]init];
UINavigationController *searchNavCon = [[UINavigationController alloc]initWithRootViewController:searchTableCon];
searchTableCon.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Search"
image:[UIImage imageNamed:#"Search"]
selectedImage:[UIImage imageNamed:#"Search"]];
You will have to do following thing for this.
UIImage * selectedImage = [UIImage imageNamed:#"selected_image.png"];
selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
viewCtrl.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Title" image:selectedImage selectedImage:selectedImage];

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"]];

Resources