【问题标题】:Xamarin letter spacing in password entry密码输入中的 Xamarin 字母间距
【发布时间】:2019-09-25 03:42:39
【问题描述】:

我在 ios 中为条目类型编写了自定义渲染器以添加字母空间。当没有为密码类型设置条目时,它可以工作。如何实现密码输入的这种行为?

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

        var element = Element as PassowrdEntry;
        if (element == null)
            return;

        if (!string.IsNullOrEmpty(Element.Text))
        {
            Control.AttributedText = new NSAttributedString(Element.Text, new UIStringAttributes
            {
                Font = Control.Font,
                KerningAdjustment = 8
            });
        }

    }

【问题讨论】:

  • 你想要在字符串的开头、中间或结尾处的字母空格“黑色字符串”?
  • @HimanshuDwivedi 想在每个输入的密码字母之间添加空格。
  • 添加空间将自动完成,或者您希望用户在输入密码时应该能够输入空间
  • @HimanshuDwivedi 我想要的是在密码字母(圆点)之间添加字母空格。不加空格
  • @IshanthaKamal 您好,您可以将您的AttributedText 代码执行到Control.TextChanged 方法中试一试。

标签: xamarin xamarin.forms xamarin.ios


【解决方案1】:

对我来说它正在工作,我只是将 KerningAdjustment 的值增加到 10。

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
    base.OnElementPropertyChanged(sender, e);

    var element = Element as CustomEntry;
    if (element == null)
        return;

    if (!string.IsNullOrEmpty(Element.Text))
    {
        Control.AttributedText = new NSAttributedString(Element.Text, new UIStringAttributes
        {
            Font = Control.Font,
            KerningAdjustment = 10
        });
    }
}

Xaml:

<ctrl:CustomEntry Placeholder="Enter Pass"
                  IsPassword="True"/>

【讨论】:

  • 我真正想要的是增加字母之间的空间。而不是增加空间。我已经为 andriod 编写了一个客户渲染器,但与 ios 渲染器的代码示例一样,它仅在未启用 IsPassword 模式时才有效。
  • 嗨@Himanshu Dwivedi。我可以知道您使用的 xamarin 表单版本吗?因为更新值后它不起作用
  • 我的 Xamarin 4.0 版
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-05
  • 2014-03-02
  • 2017-05-17
  • 2013-10-19
  • 2012-10-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多