You can use Gestures.

label.AddGestureRecognizer(new UILongPressGestureRecognizer(this, new
Selector("longTap:")));
 label.AddGestureRecognizer(new UISwipeGestureRecognizer(this, new
Selector("labelSwipe")) {
                    Direction = UISwipeGestureRecognizerDirection.Right,
                    NumberOfTouchesRequired = 1
                });

//this one is needed or nothing happens
label.UserInteractionEnabled = true;

[Export("labelSwipe")]
        public void SwipeOnLabel(UISwipeGestureRecognizer sender)
        {
            if (sender.State == UIGestureRecognizerState.Ended)
            {

....

        [Export("longTap:"), Preserve]
        public void LongTap(UILongPressGestureRecognizer sender)
        {


On Tue, Jun 26, 2012 at 11:35 PM, Chris_M <[email protected]> wrote:
>
> Yeah, I ended up going with the button that is just text approach. It seemed
> to make the most sense.
>
> I hadn't thought about subclassing UILabel, though. I don't know why, given
> that I subclass the various view controllers all the time. I guess it's just
> a reflection of my generally weak Object-Oriented Fu. I took the classes,
> but I don't tend to think object-oriented enough (most of my work experience
> has been procedural scripting, and you were right in your other reply about
> that).
>
> Anyway, I'm glad you mentioned subclassing UILabel, because I think that
> will help me pull off something else I was thinking about trying.
>
>
> --Chris
>
>
> rnendel11 wrote
>>
>> Why not just create a uibutton (by default they are "custom") that is just
>> text?
>>
>> Otherwise, you really need to subclass UILabel and override the touches
>> the expose an event... something akin to
>>
>> public class MyTouchableLabel : UILabel
>> {
>>    public MyTouchableLabel(RectangleF rect) : base(rect)
>>    {
>>       blah blah
>>    }
>>
>>    public event EventHandler OnTouched;
>>
>>    private void RaiseOnTouched()
>>    {
>>    }
>>
>>    private void TouchesBegan()
>>    {
>>       // detect touched here and "raise" the event
>>    }
>> }
>>
>> *** note *** I've seen/had many issues with handling large-scale
>> operations in touch-events that lead to custom-event handling (such as
>> above) - far better luck simply utilizing what's available in unique ways
>> - for example, use a UIButton and just latch onto the "TouchUpInside"
>> event - by default, when you create a UIButton via the standard
>> constructor it is borderless and pretty much blank - you can set the title
>> and other characteristics and simply leverage the events already generated
>> by the class vs. trying to execute lots of stuff within a custom event
>> associated with "TouchesBegan".  However, if you really just want a label
>> that is clickable, it's subclass and override time.
>>
>
>
> --
> View this message in context: 
> http://monotouch.2284126.n4.nabble.com/How-to-use-a-UILabel-as-a-button-tp4655352p4655594.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch



-- 
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

Earnest: Self-employed? Track your business expenses and income.
http://earnestapp.com
Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to