天天看點

iOS TextField Placeholder設定顔色

+(void)setPlaceholderColor:(UITextField *)textfield withPlaceholderText:(NSString *)holderText withColor:(UIColor *)color withFont:(UIFont *)font
{
    NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc]initWithString:holderText];
    [placeholder addAttribute:NSForegroundColorAttributeName
                        value:color
                        range:NSMakeRange(0, holderText.length)];
    [placeholder addAttribute:NSFontAttributeName
                        value:[UIFont boldSystemFontOfSize:15]
                        range:NSMakeRange(0, holderText.length)];
    textfield.attributedPlaceholder = placeholder;
 
}
           
iOS