I have an Entry in Xamarin Forms and for Android, its displayed with an underline by default and when I test it for iOS it's always with a rectangle like this:
And I want it to be like just like in Android:
I used Custom render where I specified that I want an underline but its still displayed in a rectangle. This code doesn't work:
class MyEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.BorderStyle = UITextBorderStyle.Line;
}
}
}
I have solved this problem with the next code:
class MyEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.BorderStyle = UITextBorderStyle.None;
//Create borders(bottom only)
CALayer border = new CALayer();
float width = 2.0f;
border.BorderColor = Color.FromHex(ColorConstants.BlueHex).ToCGColor();
border.Frame = new CGRect( 0, 40, 400, 2.0f);
border.BorderWidth = width;
Control.Layer.AddSublayer(border);
Control.Layer.MasksToBounds = true;
}
}
}
But still, don't understand why the previous code doesn't work, it should be simple as that. Any ideas?