I used to use the following code to adjust the height of my tab bar. However after I upgrade to Xcode 11 and using swift 5, the UI doesn't appear correctly anymore.
class MyTabBarController: UITabBarController {
private lazy var defaultTabBarHeight = { [unowned self] in
return self.tabBar.frame.size.height
}()
let higherTabBarInset: CGFloat = 24
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
let newTabBarHeight = defaultTabBarHeight + higherTabBarInset
var newFrame = tabBar.frame
newFrame.size.height = newTabBarHeight
newFrame.origin.y = view.frame.size.height - newTabBarHeight
tabBar.items?.forEach({e in
e.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -(higherTabBarInset / 2))
})
}
}
It is supposed to appear like this, with the height of tab bar being 72:
However using Xcode 11 it looks like this in iOS 12, the tab bar height goes back to the default 49:
and in iOS 13, it displays like in .inlineLayoutAppearance
even if my app was set for portrait layout only and the target device is iPhone only. My customised font also goes back to the system default one, too. Like in iOS 12, the UITabBar height goes back to default 49:
I referred to this similar question but the solution doesn't work for me, and it doesn't look like a proper solution anyway.
Another thing I don't understand related to this is that, when I tried to set the UITabBarItem's appearance with the following code:
tabBar.items?.forEach({e in
if #available(iOS 13.0, *) {
let appearance = UITabBarItemAppearance()
appearance.configureWithDefault(for: .stacked)
e.standardAppearance = appearance
}
})
I got an error saying that Cannot assign value of type 'UITabBarItemAppearance' to type 'UITabBarAppearance?
. Then I found that even if the type of my iteration variable e
is UITabBarItem
, the type of its appearance is UITabBarAppearance?
... I couldn't figure out a way to set my UITabBarItem's appearance either, which is really confusing...
Does anyone know if there is any reasonable reason for this, or it's a possible bug here? Thanks ahead for any answer.