An easy-to-use UISearchController. iOS11 style compatible with iOS10.
Dwonload and check out the demo project.
iOS 11
iOS 11 lower
(I know the demo color pattern is kind of urgly, forgive me :D. I will improve it soon)
Download .swift
files in Source.
class ViewController: FTSearchController
Just inherit the FTSearchController
.
FTSearchController
already provide a UITableView
for you to show reuslt.
Just implement the all in one protocol FTSearchControllerDataProvider
###1. Customize UI Setup TextField
textFieldBackgroundColor
: Backgournd color oftextField
insearchControler's searchBar
textFieldCornerRadius
: corner radius of thetextField
textFieldTextColor
: text color oftextField
textFieldFont
: text font oftextField
cursorColor
: Set cursor color by changing the tint color of the searchBarattributedPlaceholder
: set up theattributedPlaceholder
of thetextField
leftIconColor
: the color of the magnifying lends in thetextField
rightIconColor
: the clear button in thetextField
Setup CancelButton
customizeCancelButton
: (UIButton)->(): a clourse help you setup the cancel buttoncencelButtonAttributedTitle
: This attribute only valid when customizeCancelButton block is nilcancelButtonColor
: This attribute only valid whencustomizeCancelButton
block andcencelButtonAttributedTitle
is nilcancelButtonTitle
: This attribute only valid whencustomizeCancelButton
block andcencelButtonAttributedTitle
is nil
Setup Bar
hideBorderLines
: wether hide the upper and lower border line of thesearchBar
barBackgroundColor
: set the search bar background, only working on iOS 11 loweruniversalBackgoundColor
: set the search bar and thenavigationBar
background. This attribute will also setsearchBar.isTranslucent
tofalse
on iOS 11 lowerhideNavitionBarBottomLine
: wether hide the bottom line of thenavigationBar
The delegate methods of UISearchBar
has been convert to closures like below
typealias EmptySearchBarHandler = (UISearchBar)->()
typealias BoolSearchBarHandler = (UISearchBar)->(Bool)
public var searchButtonClickHandler: EmptySearchBarHandler?
public var searchBarShouldBeginEditingHandler: BoolSearchBarHandler?
public var searchBarShouldEndEditingHandler: BoolSearchBarHandler?
public var searchBarCancelButtonClickHandler: EmptySearchBarHandler?
public var searchTextDidChange: ((UISearchBar, String)->())?
public var searchTextShouldChangeInRange: ((UISearchBar, NSRange, String)->(Bool))?
This protocol simply inherits UITableViewDelegate
, UITableViewDataSource
, UISearchResultUpdating
.