Large title search like appstore swift 4.2
This example of navigation title to create a large title like appstore. In order to setup the large title in the navigation bar of this controller, a new property prefersLargeTitles should be set to true, full example below in file (.swift) :
import UIKit
class LargeTitleViewController: UIViewController, UISearchResultsUpdating {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// set lerge title in navigation bar
navigationItem.title = "Search"
navigationController?.navigationBar.prefersLargeTitles = true
navigationController?.navigationItem.largeTitleDisplayMode = .never
// search in top navbar
let search = UISearchController(searchResultsController: nil)
search.searchResultsUpdater = self
self.navigationItem.searchController = search
// table cell configuration
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
func updateSearchResults(for searchController: UISearchController) {
print("Process Search in this function")
}
}
extension LargeTitleViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 30
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "tessss\(indexPath.row)"
return cell
}
}
No comments: