ios 11 UITabBar UITabBarItem positioning issue

前端 未结 7 1468
清酒与你
清酒与你 2020-12-02 13:03

I have built my app using new Xcode 9 beta for ios 11. I have found an issue with UITabBar where items are spread through the UITabBar and title is right aligned to the imag

7条回答
  •  無奈伤痛
    2020-12-02 13:38

    In Addition to John's answer:

    If you have more than 4 Tab Bar Items and don't want the "More" Button you have to take a different Size Class. And if you want the original centred layout of items you have to add another method like so:

    #import "PreIOS11TabBarController.h"
    
    @interface PreIOS11TabBarController ()
    
    @end
    
    @implementation PreIOS11TabBarController
    
    // In iOS 11, UITabBarItem's have the title to the right of the icon in horizontally regular environments
    // (i.e. the iPad).  In order to keep the title below the icon, it was necessary to subclass UITabBar and override
    // traitCollection to make it horizontally compact.
    
    - (UITraitCollection *)traitCollection {
        return [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified];
    }
    
    
    - (void)viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
    
        self.tabBar.itemPositioning = UITabBarItemPositioningCentered;
    }
    
    @end
    

提交回复
热议问题