我已经看到一些答案,显示如何通过覆盖drawPlaceholderInRect:方法来更改UITextField的placeHolder文本颜色:
iPhone UITextField – Change placeholder text color
但是并没有保持现有的属性,如对齐,字体等…什么是更好的方法来解决这个问题?
解决方法
从iOS 6,
没有任何子类化,可以通过几行代码来实现这一点:
UIColor *color = [UIColor blackColor]; textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholderText attributes:@{NSForegroundColorAttributeName: color}];