On iOS 26 not able to control size of UITabBar. Sharing code below. Colour is applying correctly but somehow _UITabBarPlatterView which turns out as TabBar is not extending; leaving spaces on left, right & bottom sides.
class CustomTabBar: UITabBar {
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .red
let firstItem = UITabBarItem(title: "Home", image: UIImage(systemName: "house"), tag: 0)
let secondItem = UITabBarItem(title: "Search", image: UIImage(systemName: "magnifyingglass"), tag: 1)
let thirdItem = UITabBarItem(title: "Profile", image: UIImage(systemName: "person.circle"), tag: 2)
items = [firstItem, secondItem, thirdItem]
selectedItem = firstItem
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class ViewController: UIViewController {
let tabBar: CustomTabBar = {
let tb = CustomTabBar()
tb.translatesAutoresizingMaskIntoConstraints = false
return tb
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
view.addSubview(tabBar)
NSLayoutConstraint.activate([
tabBar.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 25),
tabBar.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -25),
tabBar.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
])
}
}
when specifying height in CustomTabBar explicitly...
func alignInternalSubViews() {
subviews.forEach { subView in
subView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
subView.topAnchor.constraint(equalTo: topAnchor),
subView.leadingAnchor.constraint(equalTo: leadingAnchor),
subView.trailingAnchor.constraint(equalTo: trailingAnchor),
subView.bottomAnchor.constraint(equalTo: bottomAnchor),
subView.heightAnchor.constraint(equalToConstant: 62)
])
}
}
What should I need to do in order to get this capsule _UITabBarPlatterView and its subviews resize accordingly?
Why not use a UITabBarController
, and let the system handle all of the display and sizing metrics automatically for you? UITabBarViewController
has some amazing capabilities to adapt itself to different environments, so I'd suggest going that direction to set yourself up for success with both the new design and adaptability in different environments.
— Ed Ford, DTS Engineer