Search code examples
xamarin.formsxamarin.iosborder

How to set transparent border color for entry control in forms using renderer


Am using entry control and I need a transparent border color, so used render to achieve the same, but a border is always displayed. How to overcome this.

   <local:EntryExt Text="1500"></local:EntryExt>

   public class EntryExt : Entry
   {

   }

  public class EntryExtRenderer : EntryRenderer
  {
    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
    {
        base.OnElementChanged(e);
        if (Control != null)
        {
            Control.Layer.BorderColor = UIColor.Clear.CGColor;
            Control.Layer.BorderWidth = 0;
        }

    }
  }

Solution

  • If you want to remove the border, you can set the BorderStyle to UITextBorderStyle.None.

    [assembly: ExportRenderer(typeof(Entry), typeof(MyEntryRenderer))]
    namespace App650.iOS
    {
        public class MyEntryRenderer : EntryRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
            {
                base.OnElementChanged(e);
    
                if (Control != null)
                {
                    // do whatever you want to the UITextField here!
                    Control.Layer.BorderColor = UIColor.Clear.CGColor;
                    Control.Layer.BorderWidth = 0;
                    Control.BorderStyle = UITextBorderStyle.None;
                }
            }
        }
    }