0

I tried to add my own image to switch Control in xamarin forms using rendering concept but i am unable to override the existing image.Below is my code. In shared project i added code like this

  Switch switcher = new ExtendedSwitchnew();

and in ios

[assembly: ExportRenderer(typeof(ExtendedSwitchnew),typeof(SwitchRenderernew))]
namespace test.iOS
{
public class SwitchRenderernew :SwitchRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {


            UIImage imgon = UIImage.FromFile("Images/switchon.png");
            UIImage imgoff = UIImage.FromFile("Images/switchoff.png");

            Control.OnImage = imgon;
            Control.OffImage = imgoff;

        }

    }
}
}

Help me.Thanks in advace.

raji
  • 101
  • 1
  • 3
  • 13
  • 1
    Possible duplicate of [Custom UISwitch with image](http://stackoverflow.com/questions/16281735/custom-uiswitch-with-image) – SushiHangover Jul 28 '16 at 13:12
  • Thanks for your reply. The above link is related to ios but my requirement is to change the switch default image using xamarin forms (ios). – raji Aug 01 '16 at 09:41
  • If you would read the answers to the linked custom UISWitch SO, you would see that it is not possible since iOS7, In the iOS docs: `offImage/onImage : In iOS 7, this property has no effect.` : https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISwitch_Class/index.html#//apple_ref/occ/instp/UISwitch/onImage Thus you would need to create your own custom Switch-style control – SushiHangover Aug 01 '16 at 09:52

0 Answers0