Last Updated: February 25, 2016
·
1.923K
· oleggavrilov

Use native iOS events in Xamarin.iOS

To access target events, in iOS you usally use this:

[self addTarget:self action:@selector(wasPressed) forControlEvents:UIControlEventTouchDown];

Xamarin provide much smarter syntax for event wire up, because c# has much nicier EventHandlers. Here is an example:

AddTarget(OnTouchDown, UIControlEvent.TouchDown);

And OnTouchDown is this method:

private void OnTouchDown(object sender, EventArgs e)
    {
        // do your on-touch-down logic here, for example - change view's background color
    }