How to Change Floating TextField Default Placehold

2019-08-22 08:56发布

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.

Screen Shot

1条回答
Anthone
2楼-- · 2019-08-22 09:22

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,
};

enter image description here

查看更多
登录 后发表回答