iPhone UITextField - 更改占位符文本颜色 [英] iPhone UITextField - Change placeholder text color
问题描述
我想更改我在 UITextField
控件中设置的占位符文字的颜色,使其变黑。
I'd like to change the color of the placeholder text I set in my UITextField
controls, to make it black.
我更喜欢这样做而不使用普通文本作为占位符,并且必须覆盖所有方法来模仿占位符的行为。
I'd prefer to do this without using normal text as the placeholder and having to override all the methods to imitate the behaviour of a placeholder.
I相信,如果我重写此方法:
I believe if I override this method:
- (void)drawPlaceholderInRect:(CGRect)rect
然后我应该能够做到这一点。但是我不确定如何从这个方法中访问实际的占位符对象。
then I should be able to do this. But I'm unsure how to access the actual placeholder object from within this method.
推荐答案
你可以覆盖 drawPlaceholderInRect:(的CGRect)RECT
这样手动呈现占位符文本:
You can override drawPlaceholderInRect:(CGRect)rect
as such to manually render the placeholder text:
- (void) drawPlaceholderInRect:(CGRect)rect {
[[UIColor blueColor] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];
}
这篇关于iPhone UITextField - 更改占位符文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!