// 通过runtime发现UITextfield内部有一个名为_placeHolderLabel私有变量,因此可通过KVC实现类似UITextField的placeholder
// _placeholderLabel
UILabel *placeHolderLabel = [[UILabel alloc] init];
placeHolderLabel.text = @"请输入内容";
placeHolderLabel.numberOfLines = 0;
placeHolderLabel.textColor = [UIColor lightGrayColor];
[placeHolderLabel sizeToFit];
[textView addSubview:placeHolderLabel];
// 同步字体
textView.font = [UIFont systemFontOfSize:13.0];
placeHolderLabel.font = [UIFont systemFontOfSize:13.0];
[textView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
----------------------------------------------------------------------------------
打印系统类私有变量
1、引头文件
#import <objc/runtime.h>
#import <objc/message.h>
2、遍历打印出UITextView的私有变量
unsigned int count = 0;
Ivar *ivars = class_copyIvarList([UITextView class], &count);
for (int i = 0; i < count; i++)
{
Ivar ivar = ivars[i];
const char *name = ivar_getName(ivar);
NSString *objcName = [NSString stringWithUTF8String:name];
NSLog(@"%d : %@",i,objcName);
}