Cosmic Mind - How to resize view when TabsController is implemented

123 Views Asked by At

I am having a problem on inserting a title to this screen. How can I resize this view?

Here's my code where the TabsController is implemented:

    class DashboardViewController: TabsController {

    let screenSize = UIScreen.main.bounds

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func prepare() {
        super.prepare()

        tabBar.lineColor = UIColor.CustomColor.blue
        tabBar.setTabItemsColor(UIColor.CustomColor.grey, for: .normal)
        tabBar.setTabItemsColor(UIColor.CustomColor.blue, for: .selected)

        tabBarAlignment = .top
        tabBar.tabBarStyle = .auto
        tabBar.dividerColor = nil
        tabBar.lineHeight = 2.0
        tabBar.lineAlignment = .bottom
        tabBar.backgroundColor = .white
    }

}

Here's my option one code (and the option two code is the same):

    class TeamProjectViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        prepareTabItem()
        setupTableView()
    }

    fileprivate func setupTableView() {
        tableView.backgroundColor = .white
        tableView.allowsSelection = false
        tableView.separatorColor = UIColor.CustomColor.lightGrey
        tableView.register(UINib(nibName: "ProjectTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ProjectTableViewCell
        return cell
    }

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 150
    }

}

extension TeamProjectViewController {
    fileprivate func prepareTabItem() {
        tabItem.title = "Option 1"
    }
}

And here's what's happening to my tabs:

The options are way too the top of the screen:

Thank you!

2

There are 2 best solutions below

0
CosmicMind On

In your code you do not have anywhere where you are actually setting a view over the TabsController, where a title could exist. You would need to wrap the TabsController in order to accomplish this. One way, is use a ToolbarController:

let toolbarController = ToolbarController(rootViewController: myTabsController)
toolbarController.toolbar.title = "my title"

This is one way of going about your issue.

0
Orkhan Alikhanov On

If you want just 20 pixels to move the tabs below status bar you can use StatusBarController with displayStyle = .partial. That's how I workaround.

let tabsController = TabsController(viewControllers: [
        MyViewController1(),
        MyViewController2()
    ])

let statusBarController = StatusBarController(rootViewController: tabsController)
statusBarController .displayStyle = .partial
// add statusBarController to hierarchy