Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

custom tab bar swift ios

class CustomTabBarController: UITabBarController {


    override func viewDidLoad() {
        super.viewDidLoad()

        let controller1 = UIViewController()
        controller1.tabBarItem = UITabBarItem(tabBarSystemItem: .contacts, tag: 1)
        let nav1 = UINavigationController(rootViewController: controller1)

        let controller2 = UIViewController()
        controller2.tabBarItem = UITabBarItem(tabBarSystemItem: .contacts, tag: 2)
        let nav2 = UINavigationController(rootViewController: controller2)

        let controller3 = UIViewController()
        let nav3 = UINavigationController(rootViewController: controller3)
        nav3.title = ""

        let controller4 = UIViewController()
        controller4.tabBarItem = UITabBarItem(tabBarSystemItem: .contacts, tag: 4)
        let nav4 = UINavigationController(rootViewController: controller4)

        let controller5 = UIViewController()
        controller5.tabBarItem = UITabBarItem(tabBarSystemItem: .contacts, tag: 5)
        let nav5 = UINavigationController(rootViewController: controller5)

        viewControllers = [nav1, nav2, nav3, nav4, nav5]
        setupMiddleButton()  
    }

    func setupMiddleButton() {
        let menuButton = UIButton(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
        var menuButtonFrame = menuButton.frame
        menuButtonFrame.origin.y = view.bounds.height - menuButtonFrame.height - 50
        menuButtonFrame.origin.x = view.bounds.width/2 - menuButtonFrame.size.width/2
        menuButton.frame = menuButtonFrame

        menuButton.backgroundColor = UIColor.red
        menuButton.layer.cornerRadius = menuButtonFrame.height/2
        view.addSubview(menuButton)

        menuButton.setImage(UIImage(named: "example"), for: .normal)
        menuButton.addTarget(self, action: #selector(menuButtonAction(sender:)), for: .touchUpInside)

        view.layoutIfNeeded()
    }


    // MARK: - Actions

    @objc private func menuButtonAction(sender: UIButton) {
        selectedIndex = 2
    }

}

Comment

PREVIOUS NEXT
Code Example
Swift :: string value of enum swift 
Swift :: power swift 
Swift :: swift 5 get current date 
Swift :: switch case in swift language 
Swift :: uitextview placeholder uikit ios 
Swift :: rxswift combine two observables 
Swift :: Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead. 
Swift :: set white place holder color in swift 
Swift :: remove all add TapGestureRecognizer swift 
Swift :: dismiss keyboard on tap outside swiftui 
Swift :: Prime number or not program in swift basic programs 
Swift :: convert uiimage to swiftui image 
Swift :: initialize array with zero in swift 
Swift :: hstack spacing swiftui 
Swift :: how to include a library in swift 
Swift :: swift guard statement 
Swift :: abstract class in swift 
Swift :: Swift Half-Open Range 
Swift :: swift array in chunks 
Swift :: set color of indicator line in collectionview swift 
Swift :: while loops swift 
Swift :: Swift convenience Initializer 
Swift :: Create a Throwing Function Swift 
Swift :: dfghbghjjmyuhjtdcfbjj 
Swift :: Define Swift Structure 
Swift :: how to use snippets in xcode 
Swift :: Swift repeat...while Loop 
Swift :: Swap/Change Rootviewcontroller with Animation ios/swift 
Swift :: move to nect cell of collection after some time automatically in ios swift 
Ruby :: find records created in a particular month rails 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =