Re: How can I use NSTextField like a button?
Re: How can I use NSTextField like a button?
- Subject: Re: How can I use NSTextField like a button?
- From: Peter N Lewis <email@hidden>
- Date: Thu, 13 Nov 2008 09:55:41 +0900
I want to use some kind of URL text in a dialog, which the users can
click on and which should then open the browser with a specific URL.
Here is an example of how it should look like:
http://man.icalamus.net/fr/img/menu/about_unregistered.gif
I used an NSTextField with blue text and connected it to my action,
as usual. But I didn't manage to receive mouse clicks from the text
field, whatever settings I changed in IB.
Ironically, I had to solve this problem yesterday and didn't notice
this question previously until others replied today. My solution was
a very simple subclass of NSTextField:
@interface NSTextFieldClickable : NSTextField {
}
@end
@implementation NSTextFieldClickable
- (void)mouseDown:(NSEvent *)theEvent;
{
[self sendAction:[self action] to:[self delegate]];
}
@end
That's all. It's not perfect in that it doesn't handle tracking etc,
but for a URL in an about box, it's probably adequate.
Alternatively, it would be possible to add tracking as desired to
this solution (if anyway does that, I'd love a copy).
In my research, most references to clickable NSTextFields required
the field to be editable which is not the case for an about box URL
label.
Enjoy,
Peter.
--
Keyboard Maestro 3 Now Available!
Now With Status Menu triggers!
Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/> <http://download.stairways.com/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden