英文:
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);
}
答案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 ";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论