[Object-c] Uisearchbar "Cancel" button to "Cancel" change Cancel button

Source: Internet
Author: User
Purpose: Modify the "Cancel" button on the Uisearchbar to "cancel" and modify the color, character, and font theory of the Cancel button : The first view in the array is obtained by getting all view data on the Searchbar, which is to cancel  button. When you get to the button, you can change any element of the Cancel button. Code implementation:

For (UIView *viewin  [[[Searchbar subviews]objectatindex:0]subviews]) {
        if ([viewiskindofclass:[ Nsclassfromstring (@ "Uinavigationbutton") class]) {
           UIButton * Cancel = (UIButton *) view;
            [Cancel settitle:@ "cancels" forstate:uicontrolstatenormal];
             Modify text color
            [cancel Settitlecolor:[uicolorwhitecolor] forstate:uicontrolstatenormal];
            [Cancel Settitlecolor:[uicolorwhitecolor] forstate:uicontrolstatehighlighted];
            Modify button Background
            [Cancel setbackgroundimage:[uiimageimagenamed:@ "Btn_cancel.png"]forstate:uicontrolstatenormal];
            [Cancel setBackgroundImage:nilforState:UIControlStateHighlighted];
        }
    



Related Article

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.