Border Color for Editor in Xamarin.Forms

前端 未结 8 918
[愿得一人]
[愿得一人] 2020-12-29 05:06

How can i make a border color for Editor in Xamarin.Forms?

I used this link, but it works only for Android. I want it to work in all platforms!

I\'m a little

相关标签:
8条回答
  • 2020-12-29 05:51

    Here's the complete solution I used. You need three things.

    1 - A custom class that implements Editor in your forms project.

    public class BorderedEditor : Editor
    {
    
    }
    

    2 - A custom renderer for your custom Editor in your iOS project.

    public class BorderedEditorRenderer : EditorRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
        {
            base.OnElementChanged(e);
    
            if (Control != null)
            {
                Control.Layer.CornerRadius = 3;
                Control.Layer.BorderColor = Color.FromHex("F0F0F0").ToCGColor();
                Control.Layer.BorderWidth = 2;
            }
        }
    }
    

    3 - An ExportRenderer attribute in your iOS project that tells Xamarin to use your custom renderer for your custom editor.

    [assembly: ExportRenderer(typeof(BorderedEditor), typeof(BorderedEditorRenderer))]
    

    Then use your custom editor in Xaml:

    <custom:BorderedEditor Text="{Binding TextValue}"/>
    
    0 讨论(0)
  • 2020-12-29 05:51

    You will need to implement a Custom Renderer (guide from Xamarin) for each platform since customizing the BorderColor of an Entry is not yet supported in Xamarin.Forms.

    Since you've already managed to change the BorderColor on Android, you can find a solution for iOS here: http://forums.xamarin.com/discussion/comment/102557/#Comment_102557

    0 讨论(0)
提交回复
热议问题