如何在xamarin.forms中为输入单元设置左右填充

问题描述:

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

I have used custom rendering for entry cell in xamarin forms for IOS and android. How can I set left and right padding for the entry cell.

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

My custom entry cell in PCl :

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

MyEntryCell is the custom name of my entry cell.

在我的PCL中,我有:

In my PCL I have:

public class MyEntryCell:Entry
{

}

在IOS中:

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

在Android中:

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


使用此方法为输入单元格设置填充:

Use this for setting padding to an entry cell:

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中填充:

Padding in Android:

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

因此,您可以设置值以使文本从特定位置开始。

Accordingly, you can set the value to make text start from specific position.