Modify Uisearchbar's Cancel button background, search content input text box background and uisearchbar background in iOS

Source: Internet
Author: User

Reprint Please indicate source:http://blog.csdn.net/android_ls/article/details/39993433

The test mobile iOS system version number is: 6.1.3, the implementation steps are as follows:

1. Add Uisearchbar to Parent view

    _searchbar = [[Uisearchbar alloc]init];    _searchbar.frame = CGRectMake (0, 0, self.view.frame.size.width, Kseachbarh);    _searchbar.autoresizingmask = Uiviewautoresizingflexiblewidth;    _searchbar.delegate = self;    _searchbar.placeholder = @ "Please enter name, company name, company product name";    [Self.view Addsubview:_searchbar];
2. Modify the search box background
    UIImage *img = [UIImage resizedimage:@ "Find_bg.png"];    [_searchbar setbackgroundimage:img];
3. Modify the indicator icon on the left side of the search input box

[_searchbar setimage:[uiimage resizedimage:@ "Ic_search.png"] forsearchbaricon:uisearchbariconsearch state: UIControlStateNormal];

4. Modify the background of the search input text

[_searchbar setsearchfieldbackgroundimage:[uiimage imagenamed:@ "Login_btn_input_side.png"] forState: UIControlStateNormal];

Note: For the background of the search input text provided by the designer, if provided is a small square corner, according to the common sense we will use the method of stretching the middle part of the picture, tested to show the effect as follows:


If you let the designer re-provide a fixed height of the picture (such as High is 60), as the search input text background, as follows:


5, modify the Uisearchbar to the right of the Cancel button text color and background image

 #pragma mark Search box proxy method, search input box to get focus (focus)-(void) searchbartextdidbeginediting: (Uisearchbar *) searchbar{[Searchbar    Setshowscancelbutton:yes Animated:yes]; Modify the Cancel button text color and background image to the right of Uisearchbar for (UIView *searchbuttons in [Searchbar subviews]) {if ([Searchbuttons Iskindo            Fclass:[uibutton class]] {UIButton *cancelbutton = (uibutton*) searchbuttons;            Modify text color [CancelButton settitlecolor:[uicolor whitecolor] forstate:uicontrolstatenormal];                        [CancelButton Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatehighlighted]; Modify button Background [CancelButton setbackgroundimage:[uiimage resizedimage:@ "Login_btn_login.png"] Forstate:uicontrolstat            Enormal];        [CancelButton Setbackgroundimage:nil forstate:uicontrolstatehighlighted]; }    }}
Note: Modify the cancellation button text color and background image of the code snippet, be sure to put the Cancel button will show the agent method changes, otherwise the traversal can not find Ah, it will not be modified.



Modify Uisearchbar's Cancel button background, search content input text box background and uisearchbar background in iOS

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.