size of the tabBarItems in a UITabBarController

只谈情不闲聊 提交于 2020-02-07 04:08:06

问题


I have 4 tabs in my APP for iPad. The problem is that sometimes the text is bigger than the button but i have more space to use. However, the UITabBarController doesn't use all the width for the tabBarItems. Is there an option to do it?


回答1:


UITabBarController will automatically insert spaces in between. You could do two things

  1. Override UITabButton's sizeThatFits method to give it your own size
  2. Insert negative-width spaces in between

For option 2, here's some sample code I used for toolbars of UINavigationBar (and should be applicable to UITabBarController as well)

UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
space.width = -10;

[self setToolbarItems:[[NSArray alloc] initWithObjects:tab_item1,space,tab_item2, nil] animated:NO];

I'd suggest to use one space item to the left, one space item to the right and a space item for between of each tab buttons.



来源:https://stackoverflow.com/questions/15054056/size-of-the-tabbaritems-in-a-uitabbarcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!