Two methods
1: Traverse Searchbar sub-view directly, this method is not very good, because as the version upgrade its internal level may change (for example, IOS11 navigation bar, understand nature)
2: Take the private variable
UIButton *cancel = [self valueforkey:@ "_cancelbutton"];
[Cancel Settitle:@ "cancellation" forstate: UIControlStateNormal];
It's not possible to write this state.
[Cancel Settitle:@ "cancellation" forstate: uicontrolstatedisabled];
[Cancel Settitlecolor: [Uicolor blackcolor] forstate: UIControlStateNormal];
[Cancel Settitlecolor: [Uicolor blackcolor] forstate: uicontrolstatedisabled];
Cancel.titlelabel. Font = [Uifont systemfontofsize:];
Tips: How to get a private variable, here's a piece of code (see what you can guess by name)
Gets the address of the first member variable
Ivar *ivars = Class_copyivarlist([Uisearchbar class], &count);
for (int i = 0; i < count; i++) {
Ivar Ivar = * (Ivars + i);
NSLog(@ "%s", Ivar_getname(Ivar));
}
Who Copy who releases
Free (ivars);
iOS development about Uisearchbar Custom Cancel button color, font, size