Xamarin Forms: How can I add padding to a button?

前端 未结 6 1151
天涯浪人
天涯浪人 2021-02-01 19:30

I have the following XAML Xamarin.Forms.Button

I tried to add

6条回答
  •  忘了有多久
    2021-02-01 20:19

    In iOS, you can use a simple custom renderer to add a bit of padding to the button:

    [assembly: ExportRenderer(typeof(Button), typeof(iOSButtonRenderer))]
    namespace My.App.iOS.Renderers.Button
    {
        /// 
        /// A custom renderer that adds a bit of padding to either side of a button
        /// 
        public class iOSButtonRenderer : ButtonRenderer
        {
            public iOSButtonRenderer() { }
    
            protected override void OnElementChanged(ElementChangedEventArgs e)
            {
                base.OnElementChanged(e);
                Control.ContentEdgeInsets = new UIEdgeInsets(Control.ContentEdgeInsets.Top, Control.ContentEdgeInsets.Left + 10, Control.ContentEdgeInsets.Bottom, Control.ContentEdgeInsets.Right + 10);
            }
        }
    }
    

提交回复
热议问题