Akshay Kheveria
Akshay Kheveria

Reputation: 211

Add button on navigation bar in tabbed view using swift

My app's framework is like there's a navigation controller then after 2-3 view controllers i've added a tab bar controller to show the tabs. So i want to add a button on right of the navigation bar which will be shown in each and every tab. and i want to remove the back button and want to add some other button like "settings". this is my view controller: enter image description here

Upvotes: 0

Views: 1264

Answers (2)

NavinBagul
NavinBagul

Reputation: 741

In Your Main Tabbar View controller's Viewdidload method put this code

        let sideMenuButton = UIButton(type: .custom)            
        sideMenuButton.frame = CGRect(x: 10, y: 80, width: 60, height: 60)            
        sideMenuButton.setImage(#imageLiteral(resourceName: "ic_menu"), for: .normal)     
        sideMenuButton.imageEdgeInsets = UIEdgeInsets(top: 30, left: 0, bottom: 0, right: 0)
        sideMenuButton.addTarget(self, action: #selector(clk_menu), for: .touchUpInside)
        let item1 = UIBarButtonItem(customView: sideMenuButton)

So you can add side menu in all your tab Like this you can add different buttons and title

Upvotes: 0

Ramkumar chintala
Ramkumar chintala

Reputation: 958

try this line in ViewdidLoad()

self.navigationItem.backBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: Selector("actionMethodName"))

Upvotes: 1

Related Questions