简体   繁体   English

当我们在iOS13中将设备设置为横向模式时,UITabBarItem标题文本未居中对齐

[英]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.我正在我的 Objective-C iOS 应用程序中动态实现 TabBar。 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.在那,所有 TabBarItem 标题在纵向模式下正确显示,但是当我在横向模式下旋转设备时,TabBarItem 标题 position 没有集中显示。

Here I am attaching my portrait screenshot of TabBar.在这里,我附上了我的 TabBar 肖像截图。

在此处输入图像描述

And When I rotate device and showing title alignment issue is look like this当我旋转设备并显示标题 alignment 问题看起来像这样

在此处输入图像描述

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.如果我使用这个解决方案,那么它在 LandScape 模式下工作正常,但是当我在我的代码中添加这个方法时,它停止了我的 ViewController 中的暗模式支持。

So I want proper alignment into LandScape mode and also I want to support dark mode in my ViewController also.所以我想要正确的 alignment 进入 LandScape 模式,并且我也想在我的 ViewController 中支持暗模式。

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.)注意:此问题仅在 iOS13 设备和 iPhone 中发生(在所有 iPhone 设备中低于 iOS13,它工作正常,在 iPad 中,它在任何 iOS 版本中工作正常。)

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.我找到了这个问题的解决方案,你想在你的 viewController.m 文件中添加一个方法,它有一个 TabBar。

If your application supporting dark mode then you need to add this method, it will work for all iOS device如果您的应用程序支持暗模式,那么您需要添加此方法,它将适用于所有 iOS 设备

    -(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.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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