如何在 IOS Xamarin.Forms 中更改浮动 TextField 默认占位符颜色 [英] How to Change Floating TextField Default Placeholder Color in IOS Xamarin.Forms

查看:21
本文介绍了如何在 IOS Xamarin.Forms 中更改浮动 TextField 默认占位符颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用了浮动文本字段.在不知道如何更改 ios 中的默认占位符颜色.我在那里附上了屏幕截图,密码默认颜色是灰色,我必须将密码颜色更改为黑色.如果在条目中输入任何文本,则只有密码颜色更改为黑色.

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.

推荐答案

原来是MaterialEntryRenderer中的逻辑导致问题.

It turns out the problem was caused that the logic in MaterialEntryRenderer.

找到方法 SetPlaceholderColor ,它改变了 placeholderColr 渲染.

Find the method SetPlaceholderColor , it changes the placeholderColr rendering.

修改如下:

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

这篇关于如何在 IOS Xamarin.Forms 中更改浮动 TextField 默认占位符颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆