【问题标题】:How to create a top TabBar on iOS?如何在 iOS 上创建顶部 TabBar?
【发布时间】:2015-07-29 21:59:31
【问题描述】:

你能告诉我如何在 iOS 中为 iPad 创建一个顶部的 TabBar,就像这张图一样?

底部的 TabBar 对我来说没问题。但是对于顶部的 TabBar,我仍然卡住了。

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

【问题讨论】:

  • 您想将 UISegmentedControl 放在导航栏内。见stackoverflow.com/a/15383349/393009
  • 那么 UISearchBar 怎么样?
  • 用 UISearchBar 作为视图初始化一个 UIBarButtonItem 并且没有操作,然后将它添加为右栏按钮。 (我会在我完成所有工作后发布代码)

标签: ios objective-c ipad


【解决方案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
    }
}

【讨论】:

    猜你喜欢
    • 2022-01-17
    • 2019-12-23
    • 2020-09-12
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 2019-10-02
    • 1970-01-01
    • 2020-08-10
    相关资源
    最近更新 更多