Forum Xamarin.Forms

Entry Renderer

Kelve17Kelve17 Member ✭✭
edited August 2019 in Xamarin.Forms

Hi.

How can i create a iOS custom renderer for entry to look exactly the same as the android default entry ?
I've tried this but the control does not respect the bounds/limits i have decided for it.

    public class CustomEntryRenderer : EntryRenderer
    {
        private CALayer _line;

        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);
            _line = null;

            if (Control == null || e.NewElement == null)
                return;

            Control.BorderStyle = UITextBorderStyle.None;
            _line = new CALayer
            {
                BorderColor = UIColor.FromRGB(174, 174, 174).CGColor,
                BackgroundColor = UIColor.FromRGB(174, 174, 174).CGColor,
                Frame = new CGRect(0,  Frame.Height/2, Frame.Width/2, 1f)
            };

            Control.Layer.AddSublayer(_line);
        }
    }

On android :

On iOS :

Answers

  • JohnHJohnH GBMember ✭✭✭✭✭

    Why do you want it to look like a different platform? That will be confusing to iOS users.

  • Kelve17Kelve17 Member ✭✭

    Because i want the view to be the same in both systems

  • JohnHJohnH GBMember ✭✭✭✭✭

    @Kelve17 said:
    Because i want the view to be the same in both systems

    You said that, I am genuinely interested to know why?

  • ColeXColeX Member, Xamarin Team Xamurai

    The bounds is determined by the frame(width) of the entry , not by the frame of the Layer you added .

  • Kelve17Kelve17 Member ✭✭

    @JohnH said:

    @Kelve17 said:
    Because i want the view to be the same in both systems

    You said that, I am genuinely interested to know why?

    Because it is a requirement. My designer decided that she wanted the views to be equal in both systems.

  • Kelve17Kelve17 Member ✭✭

    @ColeX said:
    The bounds is determined by the frame(width) of the entry , not by the frame of the Layer you added .

    I've also used frame width but without sucess...

  • JohnHJohnH GBMember ✭✭✭✭✭

    @Kelve17 said:

    @JohnH said:

    @Kelve17 said:
    Because i want the view to be the same in both systems

    You said that, I am genuinely interested to know why?

    Because it is a requirement. My designer decided that she wanted the views to be equal in both systems.

    Sorry to hear that. Good luck!

  • Kelve17Kelve17 Member ✭✭

    @JohnH said:

    @Kelve17 said:

    @JohnH said:

    @Kelve17 said:
    Because i want the view to be the same in both systems

    You said that, I am genuinely interested to know why?

    Because it is a requirement. My designer decided that she wanted the views to be equal in both systems.

    Sorry to hear that. Good luck!

    Why? Is it a bad thing ? Im a newbie and dont really know what is good and what its not and how to "react" to some requests i get...

  • JohnHJohnH GBMember ✭✭✭✭✭

    @Kelve17 said:

    @JohnH said:

    @Kelve17 said:

    @JohnH said:

    @Kelve17 said:
    Because i want the view to be the same in both systems

    You said that, I am genuinely interested to know why?

    Because it is a requirement. My designer decided that she wanted the views to be equal in both systems.

    Sorry to hear that. Good luck!

    Why? Is it a bad thing ? Im a newbie and dont really know what is good and what its not and how to "react" to some requests i get...

    Well, in my experience users prefer a native interface. So iOS apps look like iOS, Droid like Droid. Making existing controls (like Entry) look the same as controls on a different OS is not a good user experience. Another reason not to do it could potentially be 1 star reviews (e.g. 'why does this app look like Android?!')
    I would ask why they need to be the same. Why confuse users, what is the business advantage etc.

    I hear this kind of approach often, and I always push back by explaining the above.

    But ultimately, the client is the client. If even after I have explained the above they still want to go ahead, I do it. But at least I have informed them.

  • Kelve17Kelve17 Member ✭✭

    @JohnH said:

    @Kelve17 said:

    @JohnH said:

    @Kelve17 said:

    @JohnH said:

    @Kelve17 said:
    Because i want the view to be the same in both systems

    You said that, I am genuinely interested to know why?

    Because it is a requirement. My designer decided that she wanted the views to be equal in both systems.

    Sorry to hear that. Good luck!

    Why? Is it a bad thing ? Im a newbie and dont really know what is good and what its not and how to "react" to some requests i get...

    Well, in my experience users prefer a native interface. So iOS apps look like iOS, Droid like Droid. Making existing controls (like Entry) look the same as controls on a different OS is not a good user experience. Another reason not to do it could potentially be 1 star reviews (e.g. 'why does this app look like Android?!')
    I would ask why they need to be the same. Why confuse users, what is the business advantage etc.

    I hear this kind of approach often, and I always push back by explaining the above.

    But ultimately, the client is the client. If even after I have explained the above they still want to go ahead, I do it. But at least I have informed them.

    Alright. thanks for the good explanation :D

Sign In or Register to comment.