Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
        }
    }
like image 800
Sumeet Manghani Avatar asked Aug 22 '16 14:08

Sumeet Manghani


People also ask

How to add padding to the device in Xamarin?

In Xamarin, we have a class called “Device” with an enumeration type “OS”. With this we can check on which platform we are and can set padding to that, like in the code below You can add padding on any device with this. The result will be something like this on iOS. You can write the above code in a more simple way.

What is entry in Xamarin forms?

Xamarin.Forms Entry. The Xamarin.Forms Entry is used for single-line text input. The Entry, like the Editor view, supports multiple keyboard types. Additionally, the Entry can be used as a password field.

How do I use single line text in Xamarin forms?

Single-line text or password input. The Xamarin.Forms Entry is used for single-line text input. The Entry, like the Editor view, supports multiple keyboard types. Additionally, the Entry can be used as a password field. The Entry, like other text-presenting views, exposes the Text property.

What are the default cells in Xamarin?

If you don’t need anything too complicated, you may be able to make do with Xamarin’s three default cells: EntryCell, SwitchCell, and TextCell. EntryCells have a label and a text field (known as an entry in Xamarin).


1 Answers

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.

like image 66
Himanshu Dwivedi Avatar answered Sep 18 '22 16:09

Himanshu Dwivedi