IOS uisearchbar Modify placeholder font color and size

Source: Internet
Author: User

When I modify the placeholder font color above the searchbar, my own handwritten code is exactly the same as the correct one, it doesn't recognize it, it always collapses, and the wrong content says it's not the value, it's a hell of a thing. When I paste it over, it's fine. Love, that's what it is ... the

.. .....

 Self.searchbar = [[Uisearchbar alloc]initwithframe:cgrectmake (kuiscreen_width-40, 30)];
    _searchbar.placeholder = @ "qualified";
    _searchbar.tintcolor = [Uicolor Whitecolor];
    _searchbar.translucent = YES;
    _searchbar.layer.maskstobounds = YES;
    _searchbar.layer.cornerradius = 5.0;
    _searchbar.alpha = 0.2;
    Add a background image, you can remove the gray part of the outer box [_searchbar setbackgroundimage:[uiimage New]];

    [_searchbar Settranslucent:yes];
    This enumeration can be modified for searchbar _searchbar.searchbarstyle = uisearchbarstyleprominent;
    Previous effects, such as the following first effect diagram//plus the following command effect Searchbar.bartintcolor = [Uicolor Whitecolor]; Add a background image to the TextField in Searchbar [_searchbar setsearchfieldbackgroundimage:[uiimage imagenamed:@ "BackgroundImage"]
    Forstate:uicontrolstatenormal];
    The code modifies the color and size of the placeholder font Uitextfield * Searchfield = [_searchbar valueforkey:@ "_searchfield"];
    [Searchfield setvalue:[uicolor Redcolor] forkeypath:@ "_placeholderlabel.textcolor"]; [Searchfield Setvalue:[uifonT boldsystemfontofsize:16] forkeypath:@ "_placeholderlabel.font"];
 [Topbackimageview AddSubview:self.searchBar];

Before the effect

After the effect

Other:

#import "ViewController.h" @interface Viewcontroller () <UISearchBarDelegate> @property (nonatomic, Strong)
Uisearchbar * SEARCHBAR;

    @end @implementation Viewcontroller-(void) viewdidload {[Super viewdidload];
    Self.searchbar = [[Uisearchbar alloc]initwithframe:cgrectmake (20, 80, 300, 50)]; The default white search box, the more out of the background is gray;
    Uibarstyledefault default Uibarstyleblack background is black _searchbar.barstyle = Uibarstyledefault;
    Set the overall style of the search box to not display the background, the default is prominent display _searchbar.searchbarstyle = Uisearchbarstyledefault;
    Set the text of the search box _searchbar.text = @ "search box";
    A line of text//_searchbar.prompt = @ "Prompt" displayed at the top of the Searchbar;
    Placeholder _searchbar.placeholder = @ "placeholder";
    Set the color of the cursor in the search box to yellow _searchbar.tintcolor = [Uicolor Yellowcolor];
    Sets the background color of the search box _searchbar.bartintcolor = [Uicolor Redcolor];

    Set whether transparent _searchbar.translucent = YES;
    _searchbar.showscancelbutton = YES;

    _searchbar.showsbookmarkbutton = YES; Sets the position of the search box TextField, and the other controls are not changed _SEARCHBAR.SEARCHFIELDBAckgroundpositionadjustment = Uioffsetmake (50, 0);

    Sets the position of text in field in TextField _searchbar.searchtextpositionadjustment = Uioffsetmake (50, 0); Customize the search box magnifier icon [_searchbar setimage:[uiimage imagenamed:@ "1"] forsearchbaricon:uisearchbariconsearch state:

    UIControlStateNormal]; Set the settings for the bookmark icon [_searchbar setimage:[uiimage imagenamed:@ "2"] forsearchbaricon:uisearchbariconbookmark state:

    UIControlStateNormal];

    _searchbar.delegate = self;

[Self.view AddSubview:self.searchBar]; #pragma mark-uisearchbardelegate/* Calls Bookmarkbutton's click Method, you need to set Showsbookmarkbutton = YES, And Showssearchresultsbutton cannot be set to Yes, otherwise the Bookmarkbutton will not be displayed, causing the method//To be unable to invoke the button of a book on the right side of the search box, the default is no, _

Searchbar.showsbookmarkbutton = YES;
Call Resultslistbutton's click Method, set Showssearchresultsbutton = YES; Called when the search box is about to start using.
 Yes means the search box can be used, the default is yes otherwise the search box cannot use _searchbar.showssearchresultsbutton = yes;
    * *-(BOOL) searchbarshouldbeginediting: (Uisearchbar *) searchbar{NSLog (@ "Shouldbegin");
return YES; //When searchingWhen the cable box starts editing, it calls-(void) searchbartextdidbeginediting: (Uisearchbar *) searchbar{NSLog (@ "Didbegin");
///When the search box is about to end using.

    -(BOOL) searchbarshouldendediting: (Uisearchbar *) searchbar{NSLog (@ "Shouldend");
return YES;

///When the search box ends editing, call-(void) searchbartextdidendediting: (Uisearchbar *) searchbar{NSLog (@ "Didend");
When the content in the field changes, it starts to fall.
    -(void) Searchbar: (Uisearchbar *) Searchbar textdidchange: (NSString *) searchtext{NSLog (@ "Didchange");
        if (searchtext!= nil && searchtext.length > 0) {[self.searchdataary removeallobjects]; for (Searchmodel * model in self.originary) {if (Model.shop_name rangeofstring:searchtext options:nscaseinse
            Nsitivesearch].length > 0) {[self.searchdataary Addobject:model];
    } [Self.tableview Reloaddata];
        }else{self.searchdataary = [Nsmutablearray arrayWithArray:self.originAry];
    [Self.tableview Reloaddata]; }//Drop in field when entering, ask if input is allowed, yes is allowed, the default is yes, otherwise cannot be entered-(BOOL) Searchbar: (Uisearchbar *) Searchbar Shouldchangetextinrange: (nsrange) Range
    Replacementtext: (NSString *) text {NSLog (@ "Shouldchange");
return YES;
//Click SearchButton Call-(void) searchbarsearchbuttonclicked: (Uisearchbar *) searchbar{NSLog (@ "searchbuttonclicked");} Click Bookmarkbutton Call-(void) searchbarbookmarkbuttonclicked: (Uisearchbar *) Searchbar {NSLog (@)

Bookmarkbuttonclicked "); //Click CancelButton Call-(void) searchbarcancelbuttonclicked: (Uisearchbar *) Searchbar {NSLog (@ "CancelButton");//Click Res

 Ultslistbutton call-(void) searchbarresultslistbuttonclicked: (Uisearchbar *) searchbar{NSLog (@ "Resultslistbutton");
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.