4
iOS 8에 도입 된 새로운 UISearchController
API를 실험하고 있습니다. API가 새롭지 만 동일한 이전 UISearchBar
을 사용합니다. UINavigationController
의 titleView
에 추가했습니다.UINavigationBar 내부에 포함 된 UISearchBar 너비가 변경되지 않습니다.
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)
둘 중 어느 것도 작동하지 않습니다.
누구든지이 작업을 수행 할 다른 방법을 알고 있습니까?
감사합니다.
위대한 작품! 고맙습니다. – Isuru
도와 주셔서 감사합니다! 잘 했어! :) –
완벽한 작업. 감사! –