How to set left and right padding to an entry cell in xamarin.forms

半腔热情 提交于 2019-12-06 03:41:41

问题


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.

My custom entry cell in PCl :

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

MyEntryCell is the custom name of my entry cell.

In my PCL I have:

public class MyEntryCell:Entry
{

}

In IOS:

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

In Android :

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

回答1:


Use this for setting padding to an entry cell:

Padding in 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;

Padding in Android:

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

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



来源:https://stackoverflow.com/questions/39082015/how-to-set-left-and-right-padding-to-an-entry-cell-in-xamarin-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!