Entry transparent/clear border in iOS?

Stesvis 1,041 Reputation points
2021-04-09T16:49:07.903+00:00

Hello,
I need to make the Entry border in iOS transparent to match the look and feel of my app.

I tried with a custom renderer like this:

[assembly: ExportRenderer(typeof(Entry), typeof(NoBorderEntryRenderer))]

namespace YouRent.Mobile.iOS.Renderers
{
    public class NoBorderEntryRenderer : EntryRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Control.Layer.BorderColor = Color.Transparent.ToCGColor();
                //Control.Layer.BorderColor = UIColor.Clear.CGColor; //same as above?
            }
        }
    }

But when i run the app I still see the default gray border.
Note that I can't completely remove the border because it would make the entry box with square corners (ConerRadius=0), so this won't work for me:

Control.BorderStyle = UITextBorderStyle.None;

Is there any way to make the border transparent in iOS?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,377 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-04-12T08:26:23.76+00:00

    Hello,

    Welcome to Microsoft Q&A!

    BorderStyle = none is the only solution to remove the border , because in my test it seems to ignore BorderColor and BorderWidth property if we do nothing on BorderStyle(the default value is RoundedRect).

    If you want to both remain the ConerRadius and remove the border , you can set ConerRadius manually .

       protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)  
               {  
                   base.OnElementChanged(e);  
                   if (Control != null)  
                   {  
                       Control.BorderStyle = UITextBorderStyle.None;  
         
                       Control.Layer.CornerRadius = 5;  
                       Control.Layer.MasksToBounds = true;  
                        
                   }  
               }  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.