Re: Hyperlinks in NSTextFields?
Re: Hyperlinks in NSTextFields?
- Subject: Re: Hyperlinks in NSTextFields?
- From: Nicko van Someren <email@hidden>
- Date: Mon, 2 May 2005 11:44:50 +0100
On 2 May 2005, at 11:33, Nicko van Someren wrote:
On 1 May 2005, at 22:34, Jonathan del Strother wrote:
I'd like to add a hyperlink into an NSTextField. Is there any way of
doing so? Any alternative suggestions?
Yes. The important thing you need to do is enable rich text behaviour:
[theTextField setAllowsEditingTextAttributes: YES];
The you can just set the link attribute on the part of the text in the
field you wish to make a link:
NSMutableAttributedString *t = [[theTextField attributedStringValue]
mutableCopy];
NSDictionary *d = [NSDictionary dictionaryWithObject:
@"http://www.apple.com" forKey: NSLinkAttributeName];
[t addAttributes: d range: NSMakeRange(0, [t length])];
[theTextField setAttributedStringValue: t];
Before someone else points it out, I should add that you will also want
to do:
[t release];
since the mutable copy will be returned. The transient dictionary will
autorelease.
Nicko
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden