I have used Floating Text Field in my application. In don't know how to change the default placeholder color in ios. I have attached screenshot there the password default color is gray, I have to change the password color as black. If any text is entered in the entry that time only the password color is changed as black.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It turns out the problem was caused that the logic in MaterialEntryRenderer
.
Find the method SetPlaceholderColor
, it changes the placeholderColr rendering.
Modify it as below:
private void SetPlaceholderColor()
{
if (Element.PlaceholderColor == Color.Default)
{
Control.FloatingLabelTextColor = _defaultPlaceholderColor;
Control.AttributedPlaceholder = new NSAttributedString(Control.Placeholder, new UIStringAttributes { ForegroundColor = _defaultPlaceholderColor });
}
else {
Control.FloatingLabelTextColor = Element.PlaceholderColor.ToUIColor();
Control.AttributedPlaceholder = new NSAttributedString(Control.Placeholder, new UIStringAttributes { ForegroundColor = Element.PlaceholderColor.ToUIColor() });
}
}
Then you can change the placeholder color as you want .
var userNameEntry = new Entry()
{
Placeholder = "UserName",
PlaceholderColor = Color.Red,
TextColor = Color.Green,
};
var passwordEntry = new Entry()
{
Placeholder = "Password",
PlaceholderColor = Color.Black,
TextColor = Color.Gray,
};