1. 程式人生 > >iOS 修改TextField中的placeholder字型大小和顏色

iOS 修改TextField中的placeholder字型大小和顏色

1.在iOS6.0之前提供的attributedPlaceholder屬性:
textField.placeholder = @"請輸入使用者名稱!";
 [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
2.在iOS6.0之後提供的attributedPlaceholder屬性:
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
NSString *holderText = @"請輸入密碼!";
 NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:holderText];
 [placeholder addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, holderText.length)];
 [placeholder addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:16] range:NSMakeRange(0, holderText.length)];textField.attributedPlaceholder = placeholder;
 [cell.contentView addSubview:textField];

君凱商聯網-iOS-字唐名僧