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

前端 未结 30 2475
误落风尘
误落风尘 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条回答
  •  孤独总比滥情好
    2020-11-29 17:50

    For those who write whole UITabBarController programmatically, you can use UITabBarItem.appearance().titlePositionAdjustment to adjust the title position

    So in this case that you want add a gap between Icon and Title use it in viewDidLoad:

        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Specify amount to offset a position, positive for right or down, negative for left or up
            let verticalUIOffset = UIOffset(horizontal: 0, vertical: hasTopNotch() ? 5 : 0)
    
            UITabBarItem.appearance().titlePositionAdjustment = verticalUIOffset
        }
    

    detecting if device has Notch screen:

      func hasTopNotch() -> Bool {
          if #available(iOS 11.0, tvOS 11.0, *) {
            return UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0 > 20
          }
          return false
      }
    

提交回复
热议问题