Xamrin Forms --- buttonImage renderer-text-under-image

时间:2018-05-30 01:11:05

标签: c# c vb.net ruby-on-rails-3 xamarin

以下是iOS中自定义渲染器的代码。
我的观点是我希望文本在当时的图像下,我尝试了XLabs ImageButton,但看起来他们不再使用新的XamarinForms ....

Xamarin.iOS ......

/ *。

  

Blockquote

public class ButtonCustomRendererIOS : ButtonRenderer
    {
        public ButtonCustomRendererIOS()
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
        {
            base.OnElementChanged(e);
            if(e.NewElement !=null)
            {
                if (Control != null)
                {

#if DEBUG
                    Control.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
                    Control.VerticalAlignment   =   UIControlContentVerticalAlignment.Center;

                    Control.Layer.CornerRadius = 15;
                    Control.Layer.BorderWidth = 5;
                    Control.Layer.BorderColor = Color.Red.ToCGColor();

                    var uiImage = UIImage.FromFile(((Button)e.NewElement).Image.File);
                    var lineHeight = Control.TitleLabel.Font.LineHeight;
                    Control.ImageEdgeInsets = new UIEdgeInsets(-lineHeight, uiImage.Size.Width + (uiImage.Size.Width / 2), 0, 0);
                    Control.TitleEdgeInsets = new UIEdgeInsets(uiImage.Size.Height, -uiImage.Size.Width, 0, 0);
                    uiImage.Dispose();
#endif


                }
            }
        }
    }
  

块引用

* /。

0 个答案:

没有答案