How to change the width of UITabBarItem?

前端 未结 5 1799
醉梦人生
醉梦人生 2021-01-11 23:01

How to change the width of UITabBarItem?

I have an item with the title, that is wider than default item width. How can I fix it?

5条回答
  •  被撕碎了的回忆
    2021-01-11 23:19

    Solution for iOS7 and greater versions:

    A new property has been introduced for UITabBar: itemWidth.

    Set the itemWidth to a positive value to be used as the width for tab bar items when they are positioned as a centered group (as opposed to filling the tab bar). Default of 0 or values less than 0 will be interpreted as a system-defined width.

    @property(nonatomic) CGFloat itemWidth NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;
    

    So you can do this in your AppDelegate:

    [[UITabBar appearance] setItemWidth:WIDTH];
    

    If you want to fill the whole UITabBar:

    [[UITabBar appearance] setItemWidth:self.window.frame.size.width/NUMBER_OF_ITEMS];
    

    How to fill the UITabBar

提交回复
热议问题