question

Stesvis-5434 avatar image
0 Votes"
Stesvis-5434 asked ColeXia-MSFT answered

Entry transparent/clear border in iOS?

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?

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.