在iOS渲染器中,在选择器中向下箭头的右侧添加填充。

huangapple go评论42阅读模式
英文:

Add padding to the right of the down arrow in a picker in ios renderer

问题

我正在为Xamarin Picker添加一个向下箭头。我为此创建了一个自定义的iOS渲染器。我可以成功地显示箭头,但它与选择器的右侧相接触。如何在箭头的右侧添加一些填充空间?我在我的iOS渲染器中尝试了以下方法。

protected void UpdateBackground(UITextField control)
{
    if (control == null) return;
    control.Layer.CornerRadius = ElementV2.CornerRadius;
    control.Layer.BorderWidth = ElementV2.BorderThickness;
    control.Layer.BorderColor = ElementV2.BorderColor.ToCGColor();

    var downArrowLabel = new UILabel(new CoreGraphics.CGRect(new CoreGraphics.CGPoint(control.Frame.Size.Width - 20 - 16, 0), new CoreGraphics.CGSize(20, control.Frame.Size.Height)));
    downArrowLabel.Font = UIFont.FromName("FontAwesome", 30);
    downArrowLabel.Text = "\uf0d7";
    downArrowLabel.TextColor = UIColor.Black;
    downArrowLabel.TextAlignment = UITextAlignment.Center;
    downArrowLabel.ContentMode = UIViewContentMode.ScaleAspectFit;
    control.RightView = downArrowLabel;
    control.RightViewMode = UITextFieldViewMode.Always;
    control.RightView.Bounds = new CoreGraphics.CGRect(0, 0, 20 + 16, control.Frame.Size.Height);
}

请注意:以上代码部分不会被翻译,仅返回翻译好的内容。

英文:

I am adding a down arrow to the xamarin picker. I created a custom iOS renderer for this. I can get the arrow to show up fine, but it is touching the right hand side of the picker. How can I add some padding to the right of the arrow? I have tried the following in my ios renderer.

protected void UpdateBackground(UITextField control)
{
    if (control == null) return;
    control.Layer.CornerRadius = ElementV2.CornerRadius;
    control.Layer.BorderWidth = ElementV2.BorderThickness;
    control.Layer.BorderColor = ElementV2.BorderColor.ToCGColor();

    var downArrowLabel = new UILabel(new CoreGraphics.CGRect(new CoreGraphics.CGPoint(control.Frame.Size.Width - 20 - 16, 0), new CoreGraphics.CGSize(20, control.Frame.Size.Height)));
    downArrowLabel.Font = UIFont.FromName("FontAwesome", 30);
    downArrowLabel.Text = "\uf0d7";
    downArrowLabel.TextColor = UIColor.Black;
    downArrowLabel.TextAlignment = UITextAlignment.Center;
    downArrowLabel.ContentMode = UIViewContentMode.ScaleAspectFit;
    control.RightView = downArrowLabel;
    control.RightViewMode = UITextFieldViewMode.Always;
    control.RightView.Bounds = new CoreGraphics.CGRect(0, 0, 20 + 16, control.Frame.Size.Height);
}

在iOS渲染器中,在选择器中向下箭头的右侧添加填充。

答案1

得分: 0

I wrote a Picker renderer based on your code and tested it. I found that adding a few spaces after the Text can effectively solve this problem. It looks strange, but it works, like this

downArrowLabel.Text = "\uf0d7 ";

英文:

I wrote a Picker renderer based on your code and tested it. I found that adding a few spaces after the Text can effectively solve this problem. It looks strange, but it works, like this

downArrowLabel.Text = "\uf0d7      ";

huangapple
  • 本文由 发表于 2023年2月16日 08:52:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466816.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定