After my XCode was upgraded to 16.2, the custom bottom tabbar of iPadAPP could not be displayed properly (I set "traitOverrides.horizontalSizeClass = .compact", otherwise the tabbar would be displayed at the top and it was not the style I wanted)
Below are my code and pictures of the running effects of iOS17 and iOS18
override func viewDidLoad() {
super.viewDidLoad()
setValue(CustomTabBar(), forKey: "tabBar")
if #available(iOS 18.0, *) {
self.mode = .tabBar
self.traitOverrides.horizontalSizeClass = .compact
}
}
}
class CustomTabBar: UITabBar {
var leftView = UIView()
var rightView = UIView()
override func sizeThatFits(_ size: CGSize) -> CGSize {
var sizeThatFits = super.sizeThatFits(size)
sizeThatFits.height = 60 // 自定义高度
return sizeThatFits
}
override func layoutSubviews() {
super.layoutSubviews()
self.backgroundColor = .red
addSubview(leftView)
addSubview(rightView)
leftView.backgroundColor = .green
leftView.frame = CGRect(x: 10, y: 4, width: 80, height: 40)
rightView.backgroundColor = .green
rightView.frame = CGRect(x: 600, y: 4, width: 80, height: 40)
}
}
