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