【问题标题】:How to set left and right padding to an entry cell in xamarin.forms如何在 xamarin.forms 中为条目单元格设置左右填充
【发布时间】:2016-12-29 03:38:04
【问题描述】:

我已经为 IOS 和 android 的 xamarin 表单中的条目单元格使用了自定义渲染。如何为输入单元格设置左右填充。

我在 PCl 中的自定义输入单元格:

<local:MyEntryCell Placeholder="Placeholder" PlaceholderColor="Grey" TextColor="Black"/>

MyEntryCell is the custom name of my entry cell.

在我的 PCL 中,我有:

public class MyEntryCell:Entry
{

}

在IOS中:

namespace CustomEntry.IOS
{
   public class MyEntryCellRenderer:EntryRenderer
    {
         // override onElementChanged
    }
}

在安卓中:

namespace CustomEntry.Droid
    {
       public class MyEntryCellRenderer:EntryRenderer
        {
             // override onElementChanged
        }
    }

【问题讨论】:

  • 您的MyEntryCell 继承自什么?你不能用Padding="10,0,10,0"吗?
  • 输入单元格没有填充属性
  • 那么您可能需要在您的MyEntryCell 中设置一些填充,您能否用您的MyEntryCell 的代码更新您的问题?
  • 您的入口单元格不是入口单元格,但它派生自入口。这是一种误导,因为可用属性和构建自定义渲染器的方式完全不同。请相应地调整您的问题。

标签: xamarin.forms custom-renderer


【解决方案1】:

使用它来设置条目单元格的填充:

IOS 中的填充:

Control.LeftView = new UIView(new CGRect(0,0,15,0));
Control.LeftViewMode = UITextFieldViewMode.Always;
Control.RightView = new UIView(new CGRect(0, 0, 15, 0));
Control.RightViewMode = UITextFieldViewMode.Always;

Android 中的填充:

Control.SetPadding(15, 15, 15, 0);

相应地,您可以设置该值以使文本从特定位置开始。

【讨论】:

  • 这就是我想要的。谢谢!
  • 好的。,谢谢你的回答。
猜你喜欢
  • 1970-01-01
  • 2013-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多