通过运行时来修改我们的UITextField的Placeholder的文字颜色

来源:互联网 发布:超级捕快软件下载 编辑:程序博客网 时间:2024/04/29 23:31
////  HQTextField.m//  FunnySister////  Created by hq on 16/4/27.//  Copyright © 2016年 hanqing. All rights reserved.//#import "HQTextField.h"#import <objc/runtime.h>@implementation HQTextField//通过运行时获取我们TextField当中的一些隐含属性-(void)awakeFromNib{    //    unsigned int count=0;//    //    //获取所有的属性//    Ivar *ivars=class_copyIvarList([UITextField class], &count);//    //    for (int i=0; i<count; i++) {//        //        Ivar ivar=ivars[i];//        //        NSString *attrName=@(ivar_getName(ivar));//        //        HQLog(@"%@",attrName);//        //    }    //    free(ivars);        UILabel *label=[self valueForKey:@"_placeholderLabel"];        label.textColor=[UIColor grayColor];        //设置光标的颜色    self.tintColor=[UIColor grayColor];}-(BOOL)becomeFirstResponder{        UILabel *label=[self valueForKey:@"_placeholderLabel"];        label.textColor=self.textColor;        return [super becomeFirstResponder];}-(BOOL)resignFirstResponder{        UILabel *label=[self valueForKey:@"_placeholderLabel"];        label.textColor=[UIColor grayColor];        return [super resignFirstResponder];}@end

0 0