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