如何在UINavigationBar中添加UISegmentedControl? [英] How to add the UISegmentedControl in UINavigationBar?
问题描述
我尝试将 UISegmentedControl
添加到带有标题的 UINavigationBar
的底部。但我无法添加它,我无法在 tableView.headerView
中添加 UISegmentedControl
,因为我需要在 tableView.headerView
,所以只需要一个解决方案,我需要将 UISegmentedControl
添加到<$ c $的底部C> UINavigationBar的。任何人都有另外的想法,我可以解决这种情况吗?
I have tried to add the UISegmentedControl
to the bottom of UINavigationBar
with title. But i cannot add it and I cannot add UISegmentedControl
in the tableView.headerView
,because i need the search bar in the tableView.headerView
, so there is just one solution that i need to add UISegmentedControl
to the bottom of UINavigationBar
. Anyone have another idea that i can solve this situation?
这是我尝试过的代码(使用 Swift ):
Here is the code that I have tried(with Swift):
class searchingViewController: UITableViewController{
override func viewDidLoad() {
var items: [AnyObject] = ["Searching Method A", "Searching Method B"]
var searchSC:UISegmentedControl!
searchSC.frame = CGRectMake(0, 0, frame.width - 20, 30)
searchSC.selectedSegmentIndex = 1
searchSC.backgroundColor = UIColor(white: 1, alpha: 1)
searchSC.layer.cornerRadius = 5.0
navigateUIToolBar = UIToolbar(frame: CGRectMake(frame.minX + 10, ios7_8Info.getStatusBarHeight()+self.navigationController!.navigationBar.frame.height+frame.minY+(21/2),
frame.width - 20, 30))
navigateUIToolBar.addSubview(searchSC)
self.navigationController?.navigationBar.addSubview(navigateUIToolBar)
}
}
推荐答案
把它放入navigationBar有这样的东西左右和标题视图...使用....访问。
To put it in the navigationBar has a right left and title view for such things... accessed using....
self.navigationItem.titleView = mySegmentedControl
供将来参考....
self.navigationItem.rightBarButtonItem
self.navigationItem.leftBarButtonItems // for adding an Array of items
要将其添加到导航视图下方但将其设置为静态..添加它到viewController.view ...你在使用UITableViewController吗?如果是这样,可以切换到UIViewController并添加一个tableView,然后将您的toolbarview作为该self.view的子视图。
To add it below the navigation view but have it static.. add it to the viewController.view... Are you using a UITableViewController? If so maybe switch to a UIViewController and add a tableView then your toolbarview as subviews to that self.view.
这篇关于如何在UINavigationBar中添加UISegmentedControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!