Uitextfield placeholder for the runtime Runtime app in iOS placeholder

Source: Internet
Author: User

Runtime run-time mechanism

Runtime is a relatively low level of pure C language API, belongs to 1 C language Library, contains a lot of the underlying C language API.

In the OC code that we usually write, when the program runs, it turns into the runtime's C language code, runtime is OC's behind-the-scenes workers, the following introduction to the runtime of an application used to traverse out Uitextfield have those hidden properties, After you have found it, modify this property by KVC.

The first time you use this type of call will be called only once method, this method check the time use, and later do not

+ (void) initialize{

unsigned int count = 0;

Copies all the member variable lists Ivars is a pointer to this array and a pointer to the first element

Ivar *ivars = Class_copyivarlist ([Uitextfield class], &count);

for (int i = 0; i < count; ++i) {

The array name is actually a pointer to the first element of the array. If the pointer is to the first element of the array, you can use the pointer as an array

Ivar t = ivars[i];

Print member variable name find to _placeholderlabel

NSLog (@ "%s", Ivar_getname (t));

}

Release pointer variable ivars is copied so run out to release

Free (ivars);

}

-(Instancetype) initWithFrame: (CGRect) frame{

if (self = [Super Initwithframe:frame]) {

[Self setupui];

}

return self;

}

-(void) awakefromnib{

[Super awakefromnib];

[Self setupui];

}

-(void) setupui{

Self.textcolor = [Uicolor Whitecolor];

Tintcolor can set the color of the cursor, etc.

Self.tintcolor = Self.textcolor;

When loading this textfield, make the inside placeholder gray and let the text input box lose focus Z (because the text is dimmed when the override loses focus)

[Self resignfirstresponder];

}

When the text input box becomes the first responder, it calls the

-(BOOL) becomefirstresponder{

[Self setValue:self.textColor forkeypath:@ "_placeholderlabel.textcolor"];

return [Super Becomefirstresponder];

}

A method that is called when the text input box loses focus

-(BOOL) resignfirstresponder{

Set color by KVC Access _placeholderlabel.textcolor property

[Self setvalue:[uicolor graycolor] forkeypath:@ "_placeholderlabel.textcolor"];

return [Super Resignfirstresponder];

}

Uitextfield placeholder for the runtime Runtime app in iOS placeholder

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.