chipbk10
chipbk10

Reputation: 5955

How to create a top TabBar on iOS?

Could you please tell me how to create a TabBar on the top for iPad in iOS, like in this picture?

The bottom TabBar is ok for me. But for the top TabBar, I am still getting stuck.

Note: I am using XCode6, Objective-C, iOS8, iPad screen Thanks

enter image description here

Upvotes: 2

Views: 1126

Answers (1)

David Skrundz
David Skrundz

Reputation: 13347

I've created a new blank project and embeded the view controller in a navigation controller.

class ViewController: UIViewController {
    var segmentedControl: UISegmentedControl!
    var searchBar: UISearchBar!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Create the segmented control
        self.segmentedControl = UISegmentedControl(items: ["Active", "Due", "Trash"])
        self.segmentedControl.tintColor = UIColor.redColor()
        self.segmentedControl.sizeToFit() // Replace this with any size you want

        // Create the search bar
        self.searchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 200, height: 32))
        let rightBarButton = UIBarButtonItem(customView: self.searchBar)

        // Finally add them to the navigation item
        self.navigationItem.titleView = self.segmentedControl
        self.navigationItem.rightBarButtonItem = rightBarButton
    }
}

Upvotes: 1

Related Questions