Change the color of the placeholder of UITextField

method one:

_codeTextField . attributedPlaceholder  = [[ NSAttributedString alloc initWithString : @" Please enter the verification code (4 digits )" attributes : @{ NSForegroundColorAttributeName :[ UIColor colorWithHex : kTextLightGray ] } ];   

Method 2: KVC method

_phoneTextField . placeholder  =  @" Please enter the phone number " ;

 [_phoneTextFieldsetValue:[UIColorcolorWithHex:kTextLightGrayforKeyPath:@"_placeholderLabel.textColor"];  

 

 

 

_phoneTextField . placeholder  =  @" Please enter the phone number " ;

 This sentence needs to be placed in front of the set color. . . . . . . . . . Otherwise it doesn't work. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327057823&siteId=291194637