Change Uitabbar Height

Change tabBar height in Swift 5 for IOS 13

Try it in viewDidLayoutSubviews

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
tabBar.frame.size.height = 95
tabBar.frame.origin.y = view.frame.height - 95
}

Customise UITabBar height in Xcode11 / iOS13 or 13.1

This is how I finally solve the tab bar height problem, however the position of title is still not solved, at the moment I have to use the icon image with text instead.

@IBDesignable class MyTabBar: UITabBar {

let higherTabBarInset: CGFloat = 24

lazy var isIphoneXOrHigher: Bool = {
return UIDevice().userInterfaceIdiom == .phone && UIScreen.main.nativeBounds.height >= 2436
}()

lazy var TAB_BAR_HEIGHT: CGFloat = {
// Return according to default tab bar height
if GlobalData.isIphoneXOrHigher {
return 83 + higherTabBarInset
}
else {
return 49 + higherTabBarInset
}
}()

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
if #available(iOS 13.0, *) {
self.standardAppearance.compactInlineLayoutAppearance = UITabBarItemAppearance.init(style: .stacked)
self.standardAppearance.inlineLayoutAppearance = UITabBarItemAppearance.init(style: .stacked)
self.standardAppearance.stackedLayoutAppearance = UITabBarItemAppearance.init(style: .stacked)
self.standardAppearance.stackedItemPositioning = .centered
}
}

override init(frame: CGRect) {
super.init(frame: frame)
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
var size = super.sizeThatFits(size)
size.height = TAB_BAR_HEIGHT
return size
}

override func layoutSubviews() {
super.layoutSubviews()

self.items?.forEach({ e in
if #available(iOS 13.0, *) {
e.standardAppearance = self.standardAppearance
}
else {
e.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -(higherTabBarInset / 2))
}
})
}
}

changing the height of UITabBar in iOS7/8?

SomeGuy's answer above worked for me. Here's the Swift translation for anyone who may need it. I made the height close to what it seems most popular apps use.

class TabBar: UITabBar {

override func sizeThatFits(size: CGSize) -> CGSize {
var sizeThatFits = super.sizeThatFits(size)
sizeThatFits.height = 38

return sizeThatFits
}
}

calculating height of UITabBar

It is 320 x 49.

If you want to test, open Interface Builder, add a UITabBar, go into the ruler, you will see it

UITabBar is inherited from UIVIew so you can use the frame.size.height to get the height



Related Topics



Leave a reply



Submit