其他分享
首页 > 其他分享> > iOS13崩溃 'NSGenericException', reason: 'Access to UITextField's _placeholderLabel

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>

标签:iOS13,ivar,NSGenericException,class,Access,UITextField,whiteColor,placeholderLab
来源: https://www.cnblogs.com/Zsmile/p/11635306.html