Custom TabBarController 만들기

2021. 7. 20. 01:51아이폰 개발

크게 손대지 않고 커스텀 탭바를 만들고 싶을때 도움이 된다.

https://stackoverflow.com/questions/59091488/swift-custom-tabbar-with-center-rounded-button

 

Swift: Custom TabBar with center rounded button

I try to create custom tabbar like the below picture: Below is the result i get: Below is my current code: class CustomTabBarController: UITabBarController { override func viewDidLoad() { ...

stackoverflow.com

https://betterprogramming.pub/how-to-create-a-custom-tabbar-in-swift-d44b3db3ac0e

 

How To Create a Custom TabBar in Swift

Use the Containment API to create a TabBar we fully control

betterprogramming.pub

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
       
        if tabBarTag == true {
            self.tabBarController?.tabBar.tintColor = UIColor.red
        } else {
            self.tabBarController?.tabBar.tintColor = UIColor.blue
        }
       
    }

https://developer.apple.com/forums/thread/98947

 

How to control tab bar item color … | Apple Developer Forums

OK, I think I found a workable solution for what I am trying to do. This is still in the testing stage, but it works. To be clear, I want a specific tab bar item to take on a certain color if some condition is met. So what I did was add the following code

developer.apple.com

extension UITabBar {

override public func sizeThatFits(size: CGSize) -> CGSize {
    super.sizeThatFits(size)
    var sizeThatFits = super.sizeThatFits(size)
    sizeThatFits.height = 71 // or whatever height you need
    return sizeThatFits
   } 
}

https://stackoverflow.com/questions/23044218/change-uitabbar-height

 

Change UITabBar height

I use UITabBarController as a root view and app supports iOS 6 and above. Project class hierarchy is as below. UITabBarController - tab1 - UINavigationController - UIViewController ...

stackoverflow.com