is there any way to customise a control style in iOS using material visual?

310 views Asked by At

I'm trying to customise an Entry field for iOS platform with Visual=Material enabled.

I tried via CustomRenderer but since is iOS platform I don't know to how to reach, for example, to modify the material bottom border color without modifying the whole text color for the control.

[assembly: ExportRenderer(typeof(Entry), typeof(CustomMaterialEntryRenderer), new[] { typeof(VisualMarker.MaterialVisual) })]

    public class CustomMaterialEntryRenderer : MaterialEntryRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

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

            Layer.BorderColor = Color.FromHex("#cedee7").ToCGColor();
        }
    }

To be clear enough, just in case, I want the bottom line for example in red and text in black.

Entry Example

Thanks in advance!

1

There are 1 answers

2
Lucas Zhang On BEST ANSWER

It seems an existing issue that the CustomRenderer will never been called .We will focus on this issue .

Workaround 1:

If you just want to set the underline color of Entry . It is unnecessary to set Visual=Material.You just need to create a default Custom Renderer of Entry.

if (Control != null)
{

  Control.BorderStyle = UITextBorderStyle.None;
 
  UIView lineView = new UIView()
  {

     Frame = new CGRect(0, Element.HeightRequest - 1, Element.WidthRequest, 1),
     BackgroundColor = UIColor.Red,

  };
 
  Control.AddSubview(lineView);
 
}

Don't forget to set the WidthRequest and HeightRequest in xaml.

Workaround 2

Fortunately,there are many plugin of Material Controls from nuget. And you can download and use it directly . For example MaterialFormControls

Download the package from Nuget Manager (make sure to check the include prerelease) enter image description here

And set the property AccentColor to change the under line color

<local:MaterialEntry IsPassword="True" Placeholder="email" AccentColor="Red"/>