**Run this code on IOS 16 or below, or build with XCode 14, and when you rotate your phone landscape you get a Tab Bar with with labels below the images rather than the default of labels to the left **
extension UITabBar {
// the Master view controller shows the UITabBarItem icon next to the text
override open var traitCollection: UITraitCollection {
if UIDevice.current.userInterfaceIdiom == .pad {
return UITraitCollection(horizontalSizeClass: .compact)
}
// return super.traitCollection
if UIDevice.current.userInterfaceIdiom == .phone {
return UITraitCollection(horizontalSizeClass: .compact)
}
return super.traitCollection
}
}
_**_**Build with Xcode 15 and run on IOS 17 Iphone and you get the following error message **_**_
Thread 1: "A trait environment returned a trait collection with unspecified values for traits that are not allowed to be unspecified. This is a serious application bug and will cause undefined behavior. This issue may be caused by your class overriding the traitCollection property getter, which is not supported. Make sure to use the appropriate API if you are trying to override traits. Trait Environment: <UITabBarSwappableImageView: 0x103847660; frame = (0 0; 0 0); opaque = NO; userInteractionEnabled = NO; image = <UIImage:0x281372c70 CGImage anonymous; (34 38)@3>; layer = <CALayer: 0x282135ea0>>; Trait Collection: <UITraitCollection: 0x10386d230; HorizontalSizeClass = Compact, PreferredContentSizeCategory = L>"
_____Serious bug? more than 100,000 users over 4 years and never had an issue with this code until now. This is preventing us from building with Xcode 15 and affecting our production.
It was suggested we try this, it prevents the crash but does not work.**
____**_
`
` if UIDevice.current.userInterfaceIdiom == .phone {
if #available(iOS 17.0, *) {
return UITraitCollection(traitsFrom: [super.traitCollection, UITraitCollection(horizontalSizeClass: .compact)])
} else {
return UITraitCollection(horizontalSizeClass: .compact)
}
}
`