gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:48 25 4
gpt4 key购买 nike

你能告诉我如何在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com