Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove tab bar item text, show only image

Simple question, how can I remove the tab bar item text and show only the image?

I want the bar items to like in the instagram app:

enter image description here

In the inspector in xcode 6 I remove the title and choose a @2x (50px) and a @3x (75px) image. However the image does not use the free space of the removed text. Any ideas how to achieve the same tab bar item image like in the instagram app?

like image 529
UpCat Avatar asked Oct 21 '14 18:10

UpCat


People also ask

How do you hide the tab bar when a view controller is shown?

If you don't want that behavior, you should set hidesBottomBarWhenPushed to true where applicable. This will hide the tab bar along with any toolbars you had showing, but only when a view controller is pushed onto the navigation stack. This allows you to show the tab bar at first, then hide it when you need more room.

How do I remove the View tab bar?

Press ⇧⌘A (macOS), or Ctrl+Shift+A (Windows/Linux), for the Find Actions dialog. From here you can search for Tab Placement, NBar and TBar to turn on or off the tabs, Navigation Bar and Toolbar windows.

How do I add an image to the tab bar in iOS?

iOS UITabBarController Changing Tab Bar Item Title and Icon For a custom icon, add the required images to the assets folder and set the 'System Item' from earlier to 'custom'. Now, set the icon to be shown when the tab is selected from the 'selected image' drop down and the default tab icon from the 'image' drop down.


2 Answers

You should play with imageInsets property of UITabBarItem. Here is sample code:

let tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "more") tabBarItem.imageInsets = UIEdgeInsets(top: 9, left: 0, bottom: -9, right: 0) 

Values inside UIEdgeInsets depend on your image size. Here is the result of that code in my app:

enter image description here

like image 65
mustafa Avatar answered Oct 10 '22 13:10

mustafa


// Remove the titles and adjust the inset to account for missing title for(UITabBarItem * tabBarItem in self.tabBar.items){     tabBarItem.title = @"";     tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); } 
like image 37
ddiego Avatar answered Oct 10 '22 15:10

ddiego