UITab Bar - Selection Indicator Image - Change Position - ios

I am using a UITabBarController. In my AppDelgate I am setting the selectionIndicatorImage to a simple white line. This is showing up in the middle of the tab bar item. I want it to show in the top of my tab bar item, highlighting that it is selected. I tried making an image with a white line on top and transparent on the bottom but then it just showed up way above my tab bar. Is there a certain size I need to make this image to achieve what I am after?
Image I'm Using: https://www.dropbox.com/s/zva77z9yt6rcfsg/SelectedTab.png?dl=0
UIImage *selectedImage = [[UIImage imageNamed:#"SelectedTab"] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
[[UITabBar appearance] setSelectionIndicatorImage:selectedImage]

You have to create translucent selectedTab (see zip file) with top white line and height should be 48 Pixel
check this link https://www.dropbox.com/s/j38mqj8sd0qgv8f/selectedTab.zip?dl=0
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"selectedTab.png"]];
[[UITabBar appearance] setBarTintColor:[UIColor blackColor]];
Results:

Related

Remove status bar without making Navigation Bar shorter Objective-C

I'm making an app in which I have a navigation bar that contains a custom background image. It looks like this.
I want to remove the status bar (as it covers part of the Nav Bar image), however when I do it shortens the NavBar, like so:
I want to find a way to get rid of the status bar without shortening the nav bar and causing the image in the navBar to come all out of proportion.
Here is the code I use to set the background image of the NavBar.
[[UINavigationBar appearance] setBackgroundImage:[[UIImage imageNamed:#"navigationBar"] stretchableImageWithLeftCapWidth:0 topCapHeight:0] forBarMetrics:UIBarMetricsDefault];
Thanks!
Edit: Please note that I attempted to just change the height of the Navigation Bar, however the background image remained out of proportion.
UIImageView *logoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"yourLogoImage"]];
[logoImageView setFrame:CGRectMake(0.0f, 0.0f, 200.0f, 44.0f)];
logiImageView.contentMode = UIViewContentModeCenter;
self.navigationItem.titleView = logoImageView ;
Will fix your UIImage stretching.
EDIT:
or
self.navigationController.navigationItem.titleView = logoImageView;

How to set Image in Tabbar not Tint color in ios?

I have an application with UITabbar , I want to set image in Tabbar but am unable to set image in Tabbar. Instead of as it is image i get image shape in tint color, Is it possible to set image as it is in Tabbar? .
i have Tried this code but Unable to set image.
UITabBar *tabBar = self.tabBar;
UITabBarItem *targetTabBarItem = [[tabbar items] objectAtIndex:0]; // whichever tab-item
UIImage *selectedIcon = [UIImage imageNamed:#"name-of-selected-image.png"];
[targetTabBarItem setSelectedImage:selectedIcon];
You need to set your image attributes property Render As to Original Image. To change this select your image from assets and in the Attributes Inspector set Render As property to Original Image like this.
Select your TabBar Item and set your image like this
OR
Set selected tint color try this
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[UITabBarItem.appearance setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateNormal];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"name-of-selected-image.png"]];
[[UITabBar appearance]setSelectedItem:[[UITabBar appearance].items objectAtIndex:2]];

How to make default tab bar as full transparent

Transperent imageI am working on a tab bar application.I applied the color to the tab bar like this
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:137.0/255.0f green:27.0/255.0f blue:2.0/255.0f alpha:1.0f]];
My requirement is to display the tab bar transparent like below image
After applying the below code.tab bar is not displaying transparent. but it is displaying with black color background
self.tabBarController.tabBar.backgroundColor = [UIColor clearColor];
self.tabBarController.tabBar.translucent = YES;
Give suggestions for making the default tab bar as transperent
black color background image
You can create an empty image and pass it as a backgroundImage:
[[UITabBar appearance] setBackgroundImage:[UIImage new]];
You can use a similar approach for shadows and tint, but pay attention that a tint color is something very particular that has to deal with you whole UI.

how can I set the tintColor for the tabBar item for the unselected state

We can set UITabBar item color for the selected state with property tintColor, but how can I set the tintColor for the a tab bar item item in the unselected state?
You can set the tint color for selected and unselected tab bar buttons like this:
[[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]];
[self calculateFolderSize];
The first line sets the unselected color - red in this example - by setting the UIView's tintColor when it's contained in a tab bar. Note that this only sets the unselected image's tint color - it doesn't change the color of the text below it.
The second line sets the tab bar's selected image tint color to green.
May be it will help you.

Update foreground color of selected image in UITabBarItem

I have changed the default blue color of some selected text with setTitleTextAttributes.
However, the image still becomes blue when selected.
How can I change this behavior?
I would use UIAppearance.
[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];

Resources