Text field UI for OSX that attempt to emulate the popular Safari/Chrome Omni search bar.
BKSearchTextField is a NSTextField subclass that attempt to emulate the popular Safari/Chrome Omni search bar with listing of automatic suggestive inputs for text entry.
Simply copy the single file SearchTextField.swift to your XCode project and start enjoying all the advantages :)
// locate NSTextField in IB. Make sure it has a custom class of SearchTextField
@IBOutlet weak var pereField: SearchTextField!
pereField.filterStrings(["Jacob Portman", "Emma Bloom", "Hugh Apiston", ...])
Please find the example project included in this repo.
@IBOutlet weak var acronymTextField: SearchTextField!
acronymTextField.theme = SearchTextFieldTheme.lightTheme()
// Modify current theme properties
acronymTextField.theme.font = NSFont.systemFont(ofSize: 13)
acronymTextField.theme.bgColor = NSColor (red: 0.9, green: 0.9, blue: 0.9, alpha: 0.3)
acronymTextField.theme.borderColor = NSColor (red: 0.9, green: 0.9, blue: 0.9, alpha: 1)
acronymTextField.theme.separatorColor = NSColor (red: 0.9, green: 0.9, blue: 0.9, alpha: 0.5)
acronymTextField.theme.cellHeight = 50
// Max number of results - Default: No limit
acronymTextField.maxNumberOfResults = 5
// Max results list height - Default: No limit
acronymTextField.maxResultsListHeight = 200
// Customize highlight attributes - Default: Bold
acronymTextField.highlightAttributes = [NSBackgroundColorAttributeName: NSColor.yellow, NSFontAttributeName:NSFont.boldSystemFont(ofSize: 13)]
// Handle item selection - Default: title set to the text field
acronymTextField.itemSelectionHandler = {item in
print("got selection", item.title)
}
// Update data source when the user stops typing
acronymTextField.userStoppedTypingHandler = {
let criteria = self.acronymTextField.stringValue
if criteria.characters.count > 1 {
// Show loading indicator
self.acronymTextField.showLoadingIndicator()
self.filterAcronymInBackground(criteria) { results in
// Set new items to filter
self.acronymTextField.filterItems(results)
// Show items in filter nonetheless
self.acronymTextField.showTable()
// Stop loading indicator
self.acronymTextField.stopLoadingIndicator()
}
}
}
##Author
Benny Khoo, benny_khoo_99@yahoo.com
##Credits
BKSearchTextField was heavily inspired by another iOS sibling project by Apasccon however is optimized for keyboard interface and Cocoa.
BKSearchTextField is available under the MIT license. See the LICENSE file for more info.