[textField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
设置textfield的默认字体颜色使用KVC设置, 在iOS13系统Crash了.
原因:"NSGenericException" - reason: "Access to UITextField's _placeholderLabel ivar is prohibited. This is an application bug".
查了一下网上的文章,找到了解决问题的关键:
头文件:
#import <objc/runtime.h>
Ivar ivar = class_getInstanceVariable([UITextField class], "_placeholderLabel");
UILabel *placeholderLabel = object_getIvar(textField, ivar);
placeholderLabel.textColor = [UIColor grayColor];
这样就不会出现在暗黑模式下输入框内为白色的情况了.