Skip to content

Instantly share code, notes, and snippets.

@adamped
Created April 8, 2016 12:33
Show Gist options
  • Save adamped/f67286d1ee7b1741d442db21376678a3 to your computer and use it in GitHub Desktop.
Save adamped/f67286d1ee7b1741d442db21376678a3 to your computer and use it in GitHub Desktop.
[assembly: ExportRenderer(typeof(Label), typeof(LabelRender))]
namespace Mobile.iOS.Renderer
{
public class LabelRender : LabelRenderer
{
private class TouchLabel : UILabel
{
Label Element = null;
public TouchLabel(Label element)
{
Element = element;
this.Text = element.Text;
}
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
base.TouchesBegan(touches, evt);
foreach (var recognizer in this.Element.GestureRecognizers.Where(x => x.GetType() == typeof(PressedGestureRecognizer)))
{
var gesture = recognizer as PressedGestureRecognizer;
if (gesture != null)
if (gesture.Command != null)
gesture.Command.Execute(gesture.CommandParameter);
}
}
public override void TouchesCancelled(NSSet touches, UIEvent evt)
{
base.TouchesCancelled(touches, evt);
foreach (var recognizer in this.Element.GestureRecognizers.Where(x => x.GetType() == typeof(ReleasedGestureRecognizer)))
{
var gesture = recognizer as ReleasedGestureRecognizer;
if (gesture != null)
if (gesture.Command != null)
gesture.Command.Execute(gesture.CommandParameter);
}
}
}
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
if (Control == null)
SetNativeControl(new TouchLabel(Element) { });
base.OnElementChanged(e);
if (e.OldElement == null)
{
if (!e.NewElement.GestureRecognizers.Any())
return;
Control.UserInteractionEnabled = true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment