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
}
}
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.
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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With