reprint Please declare source: http://blog.csdn.net/jinnchang/article/details/44827923
------------------------------------------------------------------------------------------
code Example
viewcontroller.swift//uisearchbarsample////Created by Jinnchang on 15/4/1.//Copyright (c) 2015 Jinn Chang. All rights Reserved.//import Uikitclass Viewcontroller:uiviewcontroller,uisearchbardelegate {var Searchbar:uisea rchbar! Override Func Viewdidload () {super.viewdidload ()//Do any additional setup after loading the view, typical Ly from a nib. Searchbar = Uisearchbar (Frame:cgrectmake (0, Self.view.frame.size.width, +)) Searchbar.placeholder = "Search" Searchbar.prompt = "prompt" Searchbar.text = "text" Searchbar.barstyle = Uibarstyle.default se Archbar.searchbarstyle = Uisearchbarstyle.default Searchbar.bartintcolor = Uicolor.orangecolor () searchBar.t Intcolor = Uicolor.redcolor () Searchbar.translucent = True Searchbar.showsbookmarkbutton = True Searc Hbar.showscancelbutton = True Searchbar.showssearchresultsbutton = False searchbar.showsscopeBar = False searchbar.delegate = self Self.view.addSubview (searchbar)} override func Didrecei Vememorywarning () {super.didreceivememorywarning ()//Dispose of any resources the can be recreated. }//Input box Contents change Trigger event func Searchbar (Searchbar:uisearchbar, Textdidchange searchtext:string) {println ("filter: \ (SearchText)}//Bookmark button Trigger event func searchbarbookmarkbuttonclicked (Searchbar:uisearchbar) {println ("search History ")}/Cancel Button trigger event func searchbarcancelbuttonclicked (Searchbar:uisearchbar) {println (" Cancel Search ")} Search Trigger event func searchbarsearchbuttonclicked (Searchbar:uisearchbar) {println ("Start Search")}}
------------------------------------------------------------------------------------------
results show
------------------------------------------------------------------------------------------
ConclusionProject on GitHub address: uisearchbarsample
Article last updated: April 2, 2015 09:35:35. For more information, refer to:
Uisearchbar Class Reference
UIKit User Interface Catalog:search Bars
Introduction to Swift Development: Search box (Uisearchbar)