Set the color and cursor color of Uitextfield placeholders

Source: Internet
Author: User

This is in the Uitextfield class/** Runtime: Runtime can access some of the hidden properties*/+ (void) initialize{[self getivars]; [Self getProperties];}//Get all Properties+ (void) getproperties{unsignedintCount =0; objc_property_t*properties = Class_copypropertylist ([Uitextfieldclass], &count);  for(inti =0; I < count; i++) {objc_property_t property=Properties[i]; NSLog (@"%s <---->%s", Property_getname, Property_getattributes (property)); }}//get list of all member variables+ (void) getivars{unsignedintCount =0; //copy out all of the member variable lists this is an array that can access the hidden propertiesIvar *ivars = Class_copyivarlist ([Uitextfieldclass], &count);  for(inti =0; I < count; i + +) {//Ivar Ivar = * (Ivars + i);Ivar Ivar = ivars[i];//equivalent to the last sentence of codeNSLog (@"%s", Ivar_getname (Ivar)); }    //free memory because with copyFree (ivars);}//when the view is loaded- (void) awakefromnib{//UILabel *placeholderlabel = [self valueforkey:@ "_placeholderlabel"];//Placeholderlabel.textcolor = [Uicolor redcolor];//assigning values via KVC//[self setvalue:[uicolor orangecolor] forkeypath:@ "_placeholderlabel.textcolor"];//set the cursor color to match the text colorSelf.tintcolor=Self.textcolor; [Self resignfirstresponder];}//text box becomes the first responder and is discarded when you set the color of a placeholder for a text box-(BOOL) becomefirstresponder{[self setvalue:[uicolor redcolor] Forkeypath:@"_placeholderlabel.textcolor"]; return[Super Becomefirstresponder];}-(BOOL) resignfirstresponder{[self setvalue:[uicolor whitecolor] Forkeypath:@"_placeholderlabel.textcolor"]; return[Super Resignfirstresponder];}//the outside world can assign values by accessing this property- (void) Setplaceholdercolor: (Uicolor *) placeholdercolor{_placeholdercolor=Placeholdercolor; [Self setvalue:placeholdercolor forkeypath:@"_placeholderlabel.textcolor"];}

Set the color and cursor color of Uitextfield placeholders

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.