- Custom search / text input control for iOS.
- Written in Swift.
Drag the folder SMSpotlightSearView
into your Xcode project.
Note:
InspectableView is used to show some handy visual configurations in Interface Builder. Feel free to drop it if you'll do styling programmatically.
Also, if you only feel interested in the search bar, then only add SMSpotlightSearchBar.swift
to the project.
You can configure the visual presentation of both SMSpotlightSearchView or SMSpotlightSearchBar from a storyboard. E.g.
Simply use SMSpotlightSearchView(frame:)
to initialise your search view by using the default colour for dividers (the horizontal and vertical lines in search result view).
To set colour for the dividers, either use SMSpotlightSearchView(frame:, dividerColour:)
or set the dividerColour
property after the initialisation.
E.g.:
let searchView = SMSpotlightSearchView(frame: YOUR_FRAME, dividerColour: YOUR_COLOUR)
In order to do actual search and present search result, these are the delegates that should be set and implemented:
searchView.searchBar.delegate
- this is a wrapper of UITextFieldDelegate, which is used to react to editing of the search input box.
searchView.resultListTableView.dataSource
and searchView.resultListTableView.delegate
- UITableView's datasource and delegate, which is used to present result.
Regardless of whether using storyboard or not, if applying Auto Layout in your project, you will have to update the height constraint of the search view in order to show/hide the search result view.
Simply call searchView.updateSearchViewHeightWithConstraint(heightConstraint:, expandingValue:, animated:)
, which takes the height constraint and a value you would like its height to be.
E.g.:
searchView.updateSearchViewHeightWithConstraint(heightConstraint: constraint, expandingValue: YOUR_VALUE, animated: false)
The framework comes with a sample project to demonstrate how to use it.