changing the height of UITabBar in iOS7/8?

前端 未结 8 2045
轮回少年
轮回少年 2020-12-08 05:29

I am trying to change the height of the stock UITabBar to 44px, similar to Tweetbot\'s tab bar height. I\'ve also seen a few other apps do this as well.

相关标签:
8条回答
  • 2020-12-08 06:04

    If you are on iOS 11 then following will help

    -(CGSize)sizeThatFits:(CGSize)size
    {
        CGSize sizeThatFits = [super sizeThatFits:size];
        sizeThatFits.height = 60;
    
        if (@available(iOS 11.0, *)) {
            UIWindow *window = UIApplication.sharedApplication.keyWindow;
            CGFloat bottomPadding = window.safeAreaInsets.bottom;
            sizeThatFits.height += bottomPadding;
        }
    
        return sizeThatFits;
    }
    

    Basically need to cover safe area, else tabbar height on iPhone X appears to be low.

    0 讨论(0)
  • 2020-12-08 06:10

    If you have auto layout enabled, you will need to override instrinsicContentSize instead

    Proper usage of intrinsicContentSize and sizeThatFits: on UIView Subclass with autolayout

    class TabBar: UITabBar {
        override func intrinsicContentSize() -> CGSize {
            var intrinsicSize = super.frame.size
    
            intrinsicSize.height = 120
            return intrinsicSize
         }
    }
    
    0 讨论(0)
提交回复
热议问题