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 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屋!