When we use the Search bar (uisearchbar), if you set it to "shows Cancel button", there is a Cancel button on the right side of the input box (the title text is cancel).
Sometimes we want to change this button to something else, like "search." Although Searchbar does not provide a way or a property to directly modify the text of this button, we can implement it in a different way.
1, modify the text of the Searchbar Cancel button
First get the cancellation button in the Searchbar, and then set the button title can be.
Import Uikit
Class Viewcontroller:uiviewcontroller {
@IBOutlet weak var searchbar:uisearchbar!
Override Func Viewdidload () {
Super.viewdidload ()
Let UIButton = Searchbar.valueforkey ("CancelButton") as! UIButton
Uibutton.settitle ("Search", ForState:UIControlState.Normal)
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
}
}
2, modify the text color of the Searchbar Cancel button
Also get the Cancel button in the Searchbar first, then set the button Titlecolor.
Import Uikit
Class Viewcontroller:uiviewcontroller {
@IBOutlet weak var searchbar:uisearchbar!
Override Func Viewdidload () {
Super.viewdidload ()
Let UIButton = Searchbar.valueforkey ("CancelButton") as! UIButton
Uibutton.settitle ("Search", ForState:UIControlState.Normal)
Uibutton.settitlecolor (Uicolor.orangecolor (), forstate:. Normal)
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
}
}