如何在 iOS 上创建顶部 TabBar?
How to create a top TabBar on iOS?
你能告诉我如何在 iOS 中为 iPad 创建一个顶部的 TabBar 吗?
底部的 TabBar 对我来说没问题。但是对于顶部的TabBar,我还是卡住了。
注意:我使用的是XCode6、Objective-C、iOS8、iPad屏幕
谢谢
我创建了一个新的空白项目并将视图控制器嵌入到导航控制器中。
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 中为 iPad 创建一个顶部的 TabBar 吗?
底部的 TabBar 对我来说没问题。但是对于顶部的TabBar,我还是卡住了。
注意:我使用的是XCode6、Objective-C、iOS8、iPad屏幕 谢谢
我创建了一个新的空白项目并将视图控制器嵌入到导航控制器中。
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
}
}