我尝试将UISegmentedControl
添加到具有标题的UINavigationBar
底部。但我无法添加它,也无法将UISegmentedControl
添加到tableView.headerView
中,因为我需要在tableView.headerView
中使用搜索栏。因此,只有一种解决方案,那就是将UISegmentedControl
添加到UINavigationBar
底部。还有其他解决方法吗?
这是我尝试过的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)
}
}