iOS 11 iPhone X simulator UITabBar icons and titles being rendered on top covering eachother

前端 未结 30 2397
误落风尘
误落风尘 2020-11-29 17:05

Anyone having issue with the iPhone X simulator around the UITabBar component?

Mine seem to be rendering the icons and title on top of each other, I\'m not sure if I

30条回答
  •  -上瘾入骨i
    2020-11-29 17:39

    Fixed by using subclassed UITabBar to apply safeAreaInsets:

    class SafeAreaFixTabBar: UITabBar {
    
        var oldSafeAreaInsets = UIEdgeInsets.zero
    
        @available(iOS 11.0, *)
        override func safeAreaInsetsDidChange() {
            super.safeAreaInsetsDidChange()
    
            if oldSafeAreaInsets != safeAreaInsets {
                oldSafeAreaInsets = safeAreaInsets
    
                invalidateIntrinsicContentSize()
                superview?.setNeedsLayout()
                superview?.layoutSubviews()
            }
        }
    
        override func sizeThatFits(_ size: CGSize) -> CGSize {
            var size = super.sizeThatFits(size)
            if #available(iOS 11.0, *) {
                let bottomInset = safeAreaInsets.bottom
                if bottomInset > 0 && size.height < 50 {
                    size.height += bottomInset
                }
            }
            return size
        }
    }
    

提交回复
热议问题