iOS development about Uisearchbar Custom Cancel button color, font, size

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.