如何在iOS上创建顶级TabBar?

时间:2015-07-28 17:46:28

标签: ios objective-c ipad

你能否告诉我如何在iOS的iPad顶部创建一个TabBar,如图所示?

底部的TabBar对我来说还可以。但对于顶级TabBar,我仍然陷入困境。

注意:我使用的是XCode6,Objective-C,iOS8,iPad屏幕 感谢

enter image description here

1 个答案:

答案 0 :(得分:1)

我创建了一个新的空白项目,并将视图控制器嵌入导航控制器中。

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
    }
}