CustomActionIos.cs 1.46 KB
Newer Older
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
using System;
using System.Diagnostics;
using Foundation;
using ObjCRuntime;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using XAMARINCustomAction.iOS;

[assembly: Dependency(typeof(CustomActionIos))]
namespace XAMARINCustomAction.iOS
{
    public class CustomActionIos : ICustomAction
    {
        MainPage mainpage;

        public void initAccessibility(MainPage page)
        {
            mainpage = page;
            var iospage = page.GetRenderer().ViewController;

            UIAccessibilityCustomAction up = new UIAccessibilityCustomAction(name: "Increment", target: iospage, selector: new Selector("Increment:"));
            UIAccessibilityCustomAction down = new UIAccessibilityCustomAction(name: "Decrement", target: iospage, selector: new Selector("Decrement:"));
            iospage.AccessibilityCustomActions = new UIAccessibilityCustomAction[2] { up, down };

        }

        [Export("Increment:")]
        private void Increment()
        {
            int n = Int32.Parse(mainpage.counter.Text);
            Console.WriteLine($"PIPPO: clicked on increment {n}");
            Debug.WriteLine($"PIPPO: clicked on increment {n}");
            mainpage.counter.Text = "" + (n++);
        }

        [Export("Decrement:")]
        private void Decrement()
        {
            Console.WriteLine("PIPPO: clicked on decrement");
            int n = Int32.Parse(mainpage.counter.Text);
            mainpage.counter.Text = "" + (n--);
        }

    }
}