IOSCustomView 2.cs 1.38 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
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(ICustomViewRenderer), typeof(IOSCustomView))]
namespace CustomViewAccessibility.iOS
{
    public class IOSCustomView : 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;
			
        }

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


	}

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

		public override void AccessibilityElementDidBecomeFocused()
		{
			base.AccessibilityElementDidBecomeFocused();
			this.BackgroundColor = UIColor.Green;
			Console.WriteLine("PIPPO I am in focus");
		}

		public override void AccessibilityElementDidLoseFocus()
		{
			base.AccessibilityElementDidLoseFocus();
			this.BackgroundColor = UIColor.Red;
			Console.WriteLine("PIPPO I am NOT in focus");
		}
	}
}