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;

猜你喜欢

转载自blog.csdn.net/xukongjing1/article/details/80999736