0

I'm using Xamarin.Forms mixed with some native Xamarin code. Now I'd like to get a UIButton instance from a Xamarin.Forms.Button. How can I do that?

In the Clicked event handler, I can see

    void Share_Clicked(object sender, System.EventArgs e)
    {
        var button = sender as Xamarin.Forms.Button;
        if(button.EffectControlProvider != null)
        {

        }
    }

I can see EffectControlProvider.Controller is actually of UIButton type but I can't convert to it.

Is there any funciton like ToNative to get the UIButton?

Felix
  • 2,673
  • 3
  • 30
  • 38

1 Answers1

0

Refer to Referring to Native Views from Code.

#if __IOS__
    var wrapper = (Xamarin.Forms.Platform.iOS.NativeViewWrapper)contentViewButtonParent.Content;
    var button = (UIKit.UIButton)wrapper.NativeView;
    button.SetTitle("Scale and Rotate Text", UIKit.UIControlState.Normal);
    button.SetTitleColor(UIKit.UIColor.Black, UIKit.UIControlState.Normal);
#endif

Notice:this code is only used in Shared Access Project.

ColeX
  • 14,062
  • 5
  • 43
  • 240