IOSAccessibleButton.cs 1.51 KB
Newer Older
Poli97's avatar
Poli97 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
using System;
using System.ComponentModel;
using System.Reflection;
using CustomViewAccessibility;
using CustomViewAccessibility.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(IAccessibleButton), typeof(IOSAccessibleButton))]
namespace CustomViewAccessibility.iOS
{
    public class IOSAccessibleButton : ButtonRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
        {

            base.OnElementChanged(e);

            if (Control == null)
            {
                return;
            }

            Console.WriteLine("PIPPO created from IOS");
            Control.BackgroundColor = UIColor.Red;
			
        }

		protected override UIButton CreateNativeControl()
		{
			return new AccessibleButton();
		}
	}

	public class AccessibleButton : UIButton
	{
		
		public AccessibleButton() :base()
		{
			Console.WriteLine("***** AccessibleButton created *****");
		}

		public override void AccessibilityElementDidBecomeFocused()
		{
			base.AccessibilityElementDidBecomeFocused();
			this.BackgroundColor = UIColor.Green;
Paolo Pecis's avatar
Paolo Pecis committed
48
			this.SetTitle("I have the accessibility focus", UIControlState.Normal);
Poli97's avatar
Poli97 committed
49 50 51 52 53 54 55 56 57 58 59 60
			Console.WriteLine("ACCESSIBILITY I am in focus");
		}

		public override void AccessibilityElementDidLoseFocus()
		{
			base.AccessibilityElementDidLoseFocus();
			this.BackgroundColor = UIColor.Red;
			this.SetTitle("I AM NO MORE IN FOCUS", UIControlState.Normal);
			Console.WriteLine("ACCESSIBILITY I am NOT in focus");
		}
	}
}