如何更改占位符文本颜色 - iOS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16601468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How Change placeholder text color - iOS
提问by chandan
How to to change the colorof the placeholdertext I set in my UITextFieldcontrols, to make it black?
如何更改我在UITextField控件中设置的占位符文本的颜色,使其变为黑色?
回答by Vinodh
using KVC
使用 KVC
[yourtextfield setValue:[UIColor colorWithRed:120.0/255.0 green:116.0/255.0 blue:115.0/255.0 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];
you can set your own colour to placeholder
您可以将自己的颜色设置为占位符
回答by chandan
This is a best way to change your placeholder color via KVO...
这是通过 KVO 更改占位符颜色的最佳方法...
[txtEmailAddress setValue:[UIColor blackColor] forKeyPath:@"_placeholderLabel.textColor"];
I hope it helps you change placeholder color. Thanks
我希望它可以帮助您更改占位符颜色。谢谢
回答by Pradeesh Stanislavose
You can override drawPlaceholderInRect:(CGRect)rect
as such to manually render the placeholder text:
您可以重写drawPlaceholderInRect:(CGRect)rect
以手动呈现占位符文本:
- (void) drawPlaceholderInRect:(CGRect)rect {
[[UIColor blueColor] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];
}
}
回答by Xcoder
You will have to subclass the UITextField class and override the following method.
您必须继承 UITextField 类并覆盖以下方法。
- (void) drawPlaceholderInRect:(CGRect)rect
{
[[UIColor blackColor] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont italicSystemFontOfSize:17] lineBreakMode:UILineBreakModeCharacterWrap alignment:UITextAlignmentLeft];
}
回答by Vinayak Kini
Make use of the following code. which will help you.
使用以下代码。这会帮助你。
- (void) drawPlaceholderInRect:(CGRect)rect
{
[[UIColor redColor] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];
}
回答by Ahmed Z.
You can use this to change the placeholder text color.
您可以使用它来更改占位符文本颜色。
- (void) drawPlaceholderInRect:(CGRect)rect {
[[UIColor blueColor] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];
}