I have standard UITabBarController with 5 items. Everything is fine except that UITabBar does not draw selected item indicator image of first or last item from/to the edge, but keeps small space before/after it as shown in picture. I can't get rid of it and it drives me nuts. Any help is appreciated, thanks.
Asked
Active
Viewed 404 times
2
-
Is the orange actually in the image? – keji Aug 11 '15 at 17:15
-
No, it's not. It's 1px wide resizable image which is set to selectionIndicatorImage property of UITabBar. – Matthes Aug 11 '15 at 17:17
-
Does setting the tint color of the UITabBar give you the effect you want? – keji Aug 11 '15 at 17:37
-
The blue color is set as tabbar's bar tint color. – Matthes Aug 11 '15 at 17:40
-
But using `setTintColor ` should change the selected tab item's color. See -> http://stackoverflow.com/questions/19306978/setselectedimagetintcolor-not-working-in-ios-7 – keji Aug 11 '15 at 17:46
-
tintColor and barTintColor are two distinct properties. Tint color of tab bar affects how icons are drawn, tab bar uses it to colorize the icons and title. I had to set tintColor to white to get rid of this effect. – Matthes Aug 11 '15 at 17:50
-
Which SDK version are you on? – keji Aug 11 '15 at 17:52
-
Target minimum version is iOS 8.0 – Matthes Aug 11 '15 at 17:53
-
If I was you I would create a breakpoint and figure out the bounds of the UITabBarItem. Also try calling `setItemWidth` on the UITabBar and use the screen width divided by 5. – keji Aug 11 '15 at 17:57
-
Already tried that, but no luck. – Matthes Aug 11 '15 at 18:02
-
Please check https://stackoverflow.com/questions/33868139/how-to-make-uitabbar-selection-indicator-image-fill-the-whole-space – Konda Nov 01 '17 at 10:02
1 Answers
0
You should look into
UIEdgeInset
property into tabbar. Play with it a bit and you will get the hang of it.
Here's an example--
self.tabBarItem.imageInsets = UIEdgeInsetsMake(6//topOffset, 0//left, -6//bottomOffset, 0//right);
But keep in mind that whatever the value of edgeinset you give, give the opposite value to its opposite side,meaning if you give top 6, then give bottom -6 Or else the image will keep on growing or shrinking after each click.
Hope this helps

Saheb Roy
- 5,899
- 3
- 23
- 35
-
This affects only icons, not selection indicator image. Believe me, I've already tried, like everything else... – Matthes Aug 11 '15 at 17:21
-
It effects indicator image as well. You got to provide the tabbar image as a whole (along with the background) and set the image as the tabbar background image and toggle the image for selected and unselected! – Saheb Roy Aug 11 '15 at 17:41
-
So you mean I have to create 3 images, one with first item selected, one with last item selected and one for other items and handle switches and change the background image for each case? That sounds so crazy, that I can't believe it! If I'll have to go this way, I'll send very ugly email to Apple! :) – Matthes Aug 11 '15 at 17:47