简体   繁体   中英

UITabBarItem Title Text Not Align Centrally, When We Set Device in Landscape Mode in iOS13

I am implementing TabBar Dynamically in to my Objective-C iOS Application. In that, All TabBarItem Title Showing properly in Portrait mode, But when I am rotating device in Landscape mode that time TabBarItem Title position not showing centrally.

Here I am attaching my portrait screenshot of TabBar.

在此处输入图像描述

And When I rotate device and showing title alignment issue is look like this

在此处输入图像描述

For Fixing this issue i got one solution is here:

- (UITraitCollection *)traitCollection {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return [super traitCollection];
    }else{
        return [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
    }
}

If I am using this solution then it is working fine in LandScape Mode, but when i add this method in my code, it stopped dark mode support in my ViewController.

So I want proper alignment into LandScape mode and also I want to support dark mode in my ViewController also.

Note: This issue happens only in iOS13 Device and only in iPhone (below iOS13 in all iPhone device, it is working fine and in iPad, it is working fine in any iOS version.)

AnyOne Can you please help me. Any Help is Appreciate. Thanks

I found the solution of this problem, you want to add one method into your viewController.m file which have a TabBar.

If your application supporting dark mode then you need to add this method, it will work for all iOS device

    -(UITraitCollection *)traitCollection {
         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
              return [super traitCollection];
         }else{
              UITraitCollection *superSizeClass = [super traitCollection];
              UITraitCollection *verticalSizeClass = [UITraitCollection traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassRegular];

              NSArray *combinedTraitArray = [NSArray arrayWithObjects: superSizeClass,verticalSizeClass, nil];

              UITraitCollection *combinedTraits = [UITraitCollection traitCollectionWithTraitsFromCollections: combinedTraitArray];
              return combinedTraits;
        }
    }

It will work for this issue. Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM