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
How to Dismiss Viewcontroller in Swift
Rsa Implementations in Objective C
Custom Installed Font Not Displayed Correctly in Uilabel
How to Detect the Touch Event of an Uiimageview
Invalid Swift Support/Invalid Implementation of Swift
Xcode Quits Unexpectedly Every Time I Open My Project
Dyld: Symbol Not Found: _Nsurlauthenticationmethodclientcertificate When Trying to Run iOS App
Strange Generic Function Appear in View Controller After Converting to Swift 3
Automatic Preferred Max Layout Width Is Not Available on iOS Versions Prior to 8.0
How to Play a Sound Using Swift
How to Edit Empty Spaces of Left, Right Uibarbuttonitem in Uinavigationbar [iOS 7]
How to Create a Circular Progress Indicator for a Count Down Timer
Behaviour for Significant Change Location API When Terminated/Suspended
How to Check If a View Controller Is Presented Modally or Pushed on a Navigation Stack
How to Add Minutes to Current Time in Swift
iOS 13: Swift - 'Set Application Root View Controller Programmatically' Does Not Work