ios - 如何在 iOS 上创建一个顶部的 TabBar?

标签 ios objective-c ipad

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

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

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

enter image description here

最佳答案

我创建了一个新的空白项目并将 View Controller 嵌入到导航 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
    }
}

关于ios - 如何在 iOS 上创建一个顶部的 TabBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31683586/

相关文章:

ios - 使用计时器更改 UILabel 的文本

iphone - 来自一组图像的视频有 RGB 问题

objective-c - 重新加载 TableView 内容时出现 EXC_BAD_ACCES 错误

objective-c - 使用 DiskArbitration 在 OSX 中卸载磁盘

iphone - iOS 的 MIDI 文件播放库

iphone - 如何关闭我没有引用的 UIPopoverControllers?

iOS Swift - 使点击手势识别器在 View 下工作

ios - 如何调查 iOS 崩溃并出现错误 NSOSStatusErrorDomain Code=-50 "query missing class name"

ios - 在导航中使用 View Controller 添加 3D 触摸动态快速操作

objective-c - 从子 UIView 影响 UIViewController