Runtime is a relatively low-level 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, the program runs the process, in fact, is actually turned into the runtime C language code, runtime is OC's behind-the-scenes workers.
Sometimes we want to change a property of a UI control, to see if the header file is not found, when we use RunTime to see the control of some hidden or some system Apple does not want users to modify the properties
For example, we want to see some properties of Uitextfield
It's in his. m file.
Import Header File
#import <objc/runtime.h>
Use this method when you check it.
+ (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);
}
-(void) awakefromnib{
[Super awakefromnib];
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];
}
RunTime in iOS app with Uitextfield placeholder placeholder custom