How to correct Tab Bar height issue on iPhone X

前端 未结 20 3432
长发绾君心
长发绾君心 2020-12-13 13:07

I\'m having an issue with my app when testing for iPhone X. I\'m not sure how to adjust this issue, as well as not make it an issue for non iPhone X sizes. This only seems t

相关标签:
20条回答
  • 2020-12-13 13:43

    I had a a similar issue. I was setting the selectionIndicatorImage in viewDidLoad(). Moving the code to viewDidLayoutSubviews() fixed my issue.

    0 讨论(0)
  • 2020-12-13 13:45

    I was facing this cosmetic problem above iOS 11.0 and below 12.0 only.

    I was having a CustomTabBar class inherited from UITabBar. I override the frame method like below:

    - (CGRect)frame{
        return self.bounds;
    }
    

    It resolved this issue in most of the iOS version 11.0 *

    0 讨论(0)
  • 2020-12-13 13:50

    This worked for me.

    [self.tabBar.bottomAnchor constraintEqualToAnchor:self.view.layoutMarginsGuide.bottomAnchor].active = YES;
    
    0 讨论(0)
  • 2020-12-13 13:50

    Follow below guidelines for setting the UITabbar selectionIndicatorImage.

    1. UITabBar.appearance().selectionIndicatorImage = #YOUR_IMAGE
    2. Make sure your image height is 48.

    The default height of tabbar selectionIndicatorImage is 49, But in iPhone X set image height equals to 48.

    0 讨论(0)
  • 2020-12-13 13:50

    Although my answer is late, But let me ensure you, if you are facing any issue like this on iphone x, xs or max screen, Make sure the image size you are uploading as selection must have height = width * 48pxHeight.

    0 讨论(0)
  • 2020-12-13 13:51

    Create a separate file with the following code:

    extension UITabBar {
        override open func sizeThatFits(_ size: CGSize) -> CGSize {
            super.sizeThatFits(size)
            guard let window = UIApplication.shared.keyWindow else {
                return super.sizeThatFits(size)
            }
            var sizeThatFits = super.sizeThatFits(size)
            sizeThatFits.height = window.safeAreaInsets.bottom + 40
            return sizeThatFits
        }
    }
    
    0 讨论(0)
提交回复
热议问题