How to change tab bar height programmatically

房东的猫 提交于 2019-12-11 15:21:53

问题


I want to change the height of an tab bar. I changed it this way, but no change occurred.

Here's my UITabBarController:

import UIKit
import SideMenu

class TabBarController: UITabBarController {

override func viewDidLoad() {
    super.viewDidLoad()
    setupSideMenu()
    self.navigationController?.navigationBar.isHidden = true

    self.tabBar.frame = CGRect(
        origin: CGPoint(x: 0, y: 20),
        size: CGSize(width: 400, height: 200)
    )
}

回答1:


I am using an extension for changing height of tab-bar

 class CustomHeightTabBar : UITabBar {
        @IBInspectable var height: CGFloat = 0.0

        override func sizeOfTab(_ size: CGSize) -> CGSize {
            var sizeOfTab = super.sizeOfTab(size)
            if height > 0.0 {
                sizeOfTab.height = height
            }
            return sizeOfTab
        }
    }

Assign this class to tab bar

In attribute inspector

It works for me.



来源:https://stackoverflow.com/questions/47303459/how-to-change-tab-bar-height-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!