iOS13崩溃 'NSGenericException', reason: 'Access to UITextField's _placeholderLabel

<style></style>

iOS13上通过KVC设置textField的placeholder的颜色崩溃

'NSGenericException', reason: 'Access to UITextField's _placeholderLabel ivar is prohibited. This is an application bug'

 

//添加头文件

#import <objc/runtime.h>

[self.phoneTextField setValue: [UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];

//修改为
Ivar ivar = class_getInstanceVariable([UITextField class], "_placeholderLabel");
UILabel *placeholderLabel = object_getIvar(textField, ivar);
placeholderLabel.textColor = [UIColor whiteColor];

 

 

<style></style>
上一篇:使用rest-assured框架优雅实现接口测试断言


下一篇:iOS开发之--为UITextField监听数值变化的三种方法