简体   繁体   English

如何在IOS Xamarin.Forms中更改浮动文本字段默认占位符颜色

[英]How to Change Floating TextField Default Placeholder Color in IOS Xamarin.Forms

I have used Floating Text Field in my application. 我在应用程序中使用了“浮动文本字段”。 In don't know how to change the default placeholder color in ios. 在不知道如何更改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. 如果那时在该条目中输入了任何文本,则只有密码颜色会更改为黑色。

屏幕截图

It turns out the problem was caused that the logic in MaterialEntryRenderer . 原来问题是由MaterialEntryRenderer中的逻辑引起的。

Find the method SetPlaceholderColor , it changes the placeholderColr rendering. 找到方法SetPlaceholderColor ,它更改placeholderColr呈现。

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM