UITabBar width using Storyboard

Azartys

I want to get a UITabBar's width in order to get the width of an item. For this, I'm using:

let itemWidth = tabBar.frame.size.width / tabBar.items.count

However the width I get seems wrong...

The tabBar.frame.size.width gives me the width of the tabBar in the Storyboard depending of the preview...

In other words, if my Storyboard preview is set to iPad Pro 12.9", tabBar.frame.size.width will return 1024.0 even if the code is run on an iPhone 5s.

What am I missing here?

Tamás Sengel

UITabBar's dimensions will only be accurate after its layoutSubviews() function was executed. Subclass UITabBarController and access the tab bar's size in viewDidLayoutSubviews().

class CustomTabBarController: UITabBarController {
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        print(tabBar.frame.width) //this will print the actual width
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

UITabBar with blur - Storyboard

UITabBar tintColor is not changed storyboard

UIStackView : Change UIStackView image width using storyboard

UItabbar item not showing storyboard reference

How to make a button half the width of a UITableViewCell using constraints (Storyboard or Programatically)

Variable width & height of UICollectionViewCell using AutoLayout with Storyboard (without XIB)

Storyboard Global Tint UITabBar Tint changed in IOS 7.1

How to make uiview's width fit to the width of the parent view with some padding for both iphone and ipad using universal storyboard in xcode 6?

How to perform self.view.frame.size.width using storyboard in iOS for Xcode 6?

Set NSLayoutConstrain between X and width in Storyboard?

Width of button in horizontal stackview - iOS - Storyboard

UICollectionView width programatically conflicting with storyboard initialization

Using UITabBar.ItemPositioning in iOS 13

NSLocalization + Storyboard using Swift

NSWindowController Autosave using Storyboard

Using a Storyboard on a ToolTip WPF

Conditional Segue Using Storyboard

Using Storyboard ViewControllers

Using UITableView without a storyboard

Xcode 6 storyboard navigation bar width not full width for iPhone 6

iOS/xcode - How can I open a new storyboard from UITabBarController and keep the UITabBar from disappearing?

SwiftUI TabView image size does not match LaunchScreen.storyboard UITabBar, unable to fix

Add footer to UITableViewController using storyboard

Using an NSArrayController in Multiple Storyboard Scenes

WPF enlarge a rectangle using storyboard

Instantiate ViewController when using Storyboard

Using UIViewControllerAnimatedTransitioning Without Storyboard Segues

Using tilde "~" for the Storyboard names in iOS

Create Checkbox using Storyboard in Xcode