IOS中设置UITextField的placeholder的字体大小、颜色

第一种方式:

KVC的方式

    textField.placeholder = @"username is in here!";
    [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
    [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];

第二种方式:

设置 attributedPlaceholder属性

NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:@"搜索" attributes:
     @{NSForegroundColorAttributeName:[UIColor grayColor],
       NSFontAttributeName:[UIFont boldSystemFontOfSize:12]}
     ];
    searchTextField.attributedPlaceholder = attrString;

你可能感兴趣的:(IOS)