1. 程式人生 > 其它 >Object-c 修改placeholder 文字顏色

Object-c 修改placeholder 文字顏色

技術標籤:OC學習

以前:

[self.nameTextField setValue:UIColorFromRGB(0x666666) forKeyPath:@"_placeholderLabel.textColor"];

新版:

#import <objc/runtime.h>
    Ivar ivar =  class_getInstanceVariable([UITextField class], "_placeholderLabel");
    UILabel *placeholderLabel = object_getIvar(self.searchTF, ivar);
    placeholderLabel.textColor = UIColorFromRGB(0x666666);