1.設(shè)置光標(biāo)顏色
self.tintColor= [UIColorwhiteColor];
2.通過富文本設(shè)置 placeHolder
NSDictionary* attrDict =@{NSForegroundColorAttributeName: [UIColorwhiteColor]};
NSAttributedString* attributedString = [[NSAttributedStringalloc]initWithString:self.placeholder attributes:attrDict];
[selfsetAttributedPlaceholder: attributedString];
3.自定義的textField,不要自己成為自己的代理,所以監(jiān)聽事件應(yīng)該用addTarget
[selfaddTarget:selfaction:@selector(textBegin)forControlEvents:UIControlEventEditingDidBegin];
[selfaddTarget:selfaction:@selector(textEnd)forControlEvents:UIControlEventEditingDidEnd];
4.優(yōu)化placeHolder 設(shè)置顏色 的功能,不通過富文本設(shè)置,使用runTime封裝.
一般控件都是懶加載,如果placeHolder 在IB中沒有設(shè)置,那么該placeHolder控件并沒有去加載,這個(gè)時(shí)候設(shè)置顏色,是無效的;
使用runTime 原理: 先把設(shè)置的顏色存起來(動(dòng)態(tài)添加屬性),等到設(shè)置文字內(nèi)容的時(shí)候(此時(shí)控件已被加載),再把顏色傳給placeHolder(交換方法).
5.不使用代理,通知,Addtarget監(jiān)聽聚焦事件,使用系統(tǒng)內(nèi)部的方法實(shí)現(xiàn)