Search Components
InputTwo search components: TTBaseSearchBar — a styled UISearchBar without background artifacts, and TTBaseSearchView — a composite view combining a AwesomePro search icon + TTBaseUITextField with a real-time change handler.
| Class | Base | Use Case |
|---|---|---|
TTBaseSearchBar | UISearchBar | Native search bar with clean TTBaseUIKit styling |
TTBaseSearchView | TTBaseUIView | Custom icon+textfield search row with change callback |
🔍 TTBaseSearchBar
// Simple search bar
let searchBar = TTBaseSearchBar(withType: .DEF, textPlaceHolder: "Search products...")
searchBar.delegate = self
// Embed in navigation bar
navigationItem.searchController = UISearchController(searchResultsController: nil)
navigationItem.searchController?.searchBar.placeholder = "Search"
// Get underlying text field for advanced styling
let tf = searchBar.getTextField()
tf?.font = UIFont.systemFont(ofSize: 15)
🔎 TTBaseSearchView
// Default search view with icon + text field
let searchView = TTBaseSearchView()
// With placeholder and custom icon color
let searchView = TTBaseSearchView(
withIconColor: .systemBlue,
searchPlaceholder: "Search by name..."
)
// Real-time text change handler
searchView.didChangeTextSearchHandle = { [weak self] text in
self?.viewModel.filter(by: text)
}
// Add to view hierarchy
view.addSubview(searchView)
searchView.setLeadingAnchor(constant: 16)
.setTrailingAnchor(constant: 16)
.setTopAnchorWithAboveView(nextToView: titleLabel, constant: 12)
.setHeightAnchor(constant: TTSize.H_TEXTFIELD + TTSize.P_CONS_DEF * 2)
📖 API Reference
TTBaseSearchView
| Member | Type | Description |
|---|---|---|
icon | TTBaseUIImageFontView | AwesomePro search icon (left side) |
textField | TTBaseUITextField | Input field (NO_BORDER type) |
lineView | TTLineView | Optional bottom border line |
didChangeTextSearchHandle | (String) → Void | Called on every keystroke |
Pro Tip: Prefer
TTBaseSearchView over TTBaseSearchBar when you need pixel-perfect control over the search row layout. It's fully constraint-based and embeds cleanly inside panels, table headers, or custom nav bars.