Learn-iOS-Swift-by-Examples/UICatalog/Swift/UIKitCatalog/DefaultSearchBarViewControl...

54 lines
1.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:
A view controller that demonstrates how to use a default UISearchBar.
*/
import UIKit
class DefaultSearchBarViewController: UIViewController, UISearchBarDelegate {
// MARK: - Properties
@IBOutlet weak var searchBar: UISearchBar!
// MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
configureSearchBar()
}
// MARK: - Configuration
func configureSearchBar() {
searchBar.showsCancelButton = true
searchBar.showsScopeBar = true
searchBar.scopeButtonTitles = [
NSLocalizedString("Scope One", comment: ""),
NSLocalizedString("Scope Two", comment: "")
]
}
// MARK: - UISearchBarDelegate
func searchBar(searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
NSLog("The default search selected scope button index changed to \(selectedScope).")
}
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
NSLog("The default search bar keyboard search button was tapped: \(searchBar.text).")
searchBar.resignFirstResponder()
}
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
NSLog("The default search bar cancel button was tapped.")
searchBar.resignFirstResponder()
}
}