我正在尝试使用iOS 8中引入的新
我不需要搜索栏占据整个导航栏的宽度。问题是我无法调整它的大小。首先,我尝试设置搜索栏的框架。
UISearchController
API进行实验。尽管API是新的,但其使用了相同的旧的UISearchBar
。我将它添加到了UINavigationController
的titleView
中。
import UIKit
class ViewController: UIViewController, UISearchBarDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let searchController = UISearchController(searchResultsController: nil)
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.delegate = self
navigationItem.titleView = searchController.searchBar
}
}
我不需要搜索栏占据整个导航栏的宽度。问题是我无法调整它的大小。首先,我尝试设置搜索栏的框架。
searchController.searchBar.frame = CGRect(x: 0, y: 0, width: 100, height: 44)
这没起作用,所以我尝试设置titleView
的框架。
navigationItem.titleView!.frame = CGRect(x: 0, y: 0, width: 100, height: 44)
他们俩都不起作用。
有人知道其他方法吗?
谢谢。