Only image as UITabBarItem

I would like to have an icon like UITabBarItem, and not the text below it, and I was wondering if this is possible, if so, how? TIA

+17
objective-c iphone uitabbar
Aug 04 2018-12-12T00:
source share
9 answers

If you use the story panel, perhaps you can use Image Inset from the bar element size inspector and at the same time set an empty space:

enter image description here

+24
Nov 08 '14 at 17:08
source share

DELETE NAME

The easy way with the inspector

  • Choose your TabbarItem
  • The title position will change to Custom Offset
  • Set the vertical value to 100
  • Done

enter image description here

Fix IMAGE

Image Adjustment

  • Choose your TabbarItem
  • indicate Top and Bottom

enter image description here

+17
Nov 16 '15 at 3:58
source share

if you just set the image and pass nil to the header, the image will be displayed at the top level of the UITabBar element. You must also set the position.

 int offset = 7; UIEdgeInsets imageInset = UIEdgeInsetsMake(offset, 0, -offset, 0); 

After you set the icon image for the TabBarItem, you set the property value to reposition the image by doing:

 uiViewController.tabBarItem.imageInsets = imageInset; 
+15
Dec 10 '13 at 1:35
source share

Setting the item title to zero is often insufficient, because if you set the title of the view controller, it will also set the title of the panel item.

Instead, do the following:

 tabbarItem.titlePositionAdjustment = UIOffsetMake(0.f, 50.f); 
+12
Mar 07 '14 at 6:15
source share

You can use this Swift extension to define a new tabBarItemShowingOnlyImage() method that will return any UITabBarItem modified to display only the image:

 // helper for creating an image-only UITabBarItem extension UITabBarItem { func tabBarItemShowingOnlyImage() -> UITabBarItem { // offset to center self.imageInsets = UIEdgeInsets(top:6,left:0,bottom:-6,right:0) // displace to hide self.setTitlePositionAdjustment(UIOffset(horizontal:0,vertical:30000)) return self } } 

This extension is based on the tips suggested in other comments.

It hides the title, supplanting it, rather than setting it to nil , because sometimes other objects, such as the view controller itself, will set the title to some value after the tab bar item is initialized. It centers the image using imageInsets to compensate for its 6pt, the value I get is only from the eyeball on the iPhone 6 running iOS8.3.

I believe other devices and layout configurations may require a different offset correction, so the overall solution is likely to be more complex.

+4
May 6 '15 at 17:35
source share

I know that it was a long time ago. But I may have a solution to this problem.

Answer to

@ThiagoPires is only useful if the image is large enough to cover the title. Otherwise, the title will be visible below the image.

I think the easiest way to achieve this is to set the tabBarItem header to "" in your view controller code.

It is important to know that every time you change the title of a controller, the tabbaritem header will also be updated. You could take a closer look using KVO to watch the name change and set the "" to the tabbaritem accordingly. But if you do not change it in many places in your code, you can simply install it right where you change the ViewController header.

Here is an example in swift:

 override func viewDidLoad() { super.viewDidLoad() self.title = "View controller Title" self.tabBarItem.title = "" } 

What is it. I hope I can help.

+2
Apr 08 '15 at 4:14
source share

Relevant documents (highlighting mine):

initWithTitle: image: tag: Creates and returns a new element using the specified properties.

 - (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag 

Options

title: The title of the item. If nil, the title is not displayed.

image: Image of the elements. If nil, the image is not displayed. Images displayed on the tab bar are taken from this image. If this image is too large to fit on the tab bar, it is cropped to fit. The size of the image on the tab is usually 30 x 30 pixels. Alpha values ​​in the original image are used to create unselected and selected images β€” opaque values ​​are ignored.

Tag

: receiver tag, an integer that you can use to identify the objects of a bar element in your application.

Return value: a new initialized element with the specified properties.

+1
Aug 04 2018-12-12T00:
source share

like this

 UITabBarItem * personalBarItem = [[UITabBarItem alloc] init]; [personalBarItem setFinishedSelectedImage:[UIImage imageNamed:@"personal_click"] withFinishedUnselectedImage:[UIImage imageNamed:@"personal"]]; 
0
Dec 10 '13 at 2:46
source share

Try using the code below:

 UIViewController *viewController1=[[RootViewController alloc]initWithNibName:@"RootViewController" bundle:nil]; UIViewController *viewController2=[[SecondViewCtr alloc]initWithNibName:@"SecondViewCtr" bundle:nil]; UIViewController *viewController3=[[ThirdViewCtr alloc]initWithNibName:@"ThirdViewCtr" bundle:nil]; UIViewController *viewController4=[[FourthVIewCtr alloc]initWithNibName:@"FourthVIewCtr" bundle:nil]; UIViewController *viewController5=[[FIfthViewCtr alloc]initWithNibName:@"FIfthViewCtr" bundle:nil]; UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:viewController1]; UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:viewController2]; UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:viewController3]; UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:viewController4]; UINavigationController *nav5 = [[UINavigationController alloc] initWithRootViewController:viewController5]; peekArray = [[NSMutableArray alloc] init]; self.tabBarController = [[UITabBarController alloc] init]; self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1, nav2,nav3,nav4,nav5, nil]; 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 setFinishedSelectedImage:[UIImage imageNamed:@"home123.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"home_112.png"]]; [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"gift123.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"gift_112.png"]]; [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"cam12.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"cam_112.png"]]; [tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"message12.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"message_112.png"]]; [tabBarItem5 setFinishedSelectedImage:[UIImage imageNamed:@"people12.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"people_112.png"]]; [self.tabBarController setSelectedIndex:0]; self.window.rootViewController = self.tabBarController; 
0
Dec 10 '13 at 4:50
source share



All Articles