6

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
        }
    }
Sumeet Manghani
  • 71
  • 1
  • 1
  • 5
  • What does your `MyEntryCell` inherit from? Can't you just use `Padding="10,0,10,0"`? – Gerald Versluis Aug 22 '16 at 14:23
  • There is no padding attribute for entry cell – Sumeet Manghani Aug 22 '16 at 14:27
  • Then you will probably need to set some padding within your `MyEntryCell` could you please update your question with the code for your `MyEntryCell`? – Gerald Versluis Aug 22 '16 at 14:29
  • Your entry cell is not an EntryCell but it derives from Entry. This is misleading since the available properties and the way how you build a custom renderer are completely different. Please adjust your question accordingly. – hansmbakker May 18 '18 at 09:20

1 Answers1

26

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.

Himanshu Dwivedi
  • 7,934
  • 3
  • 31
  • 52