Re: Creating a Hyperlink in the UI
Re: Creating a Hyperlink in the UI
- Subject: Re: Creating a Hyperlink in the UI
- From: Nathan Kinsinger <email@hidden>
- Date: Wed, 5 Nov 2008 03:42:10 -0700
On Nov 3, 2008, at 1:25 PM, development2 wrote:
I need to create Hyperlink to the companies web site, but the link
will be in a NSTextField. How do I create a hyperlink in this text
field. I am sure it is something with NSMutableAttributedString but
can't seem to figure it out. I though maybe there was some Cocoa
class to do that, but could not find anything. Does anyone have one
or know where I might be able to find one?
Thanks in advance.
I've done it by creating an attributed string using
initWithHTML:documentAttributes: and bound it to the NSTextField. The
field should be both selectable and allows rich text. The one drawback
is no hand cursor when the mouse hovers over it.
NSDictionary *attrsDictionary = [[NSDictionary alloc]
initWithObjectsAndKeys: [NSFont labelFontOfSize:[NSFont
labelFontSize]], NSFontAttributeName, nil];
NSMutableAttributedString *htmlLinkString =
[[NSMutableAttributedString alloc] initWithHTML:[[NSString
stringWithFormat:@"<a href=\"%@\">%@</a>", self.sourceProjectURL,
self.sourceProjectURL] dataUsingEncoding: NSUTF8StringEncoding]
documentAttributes: nil];
[htmlLinkString addAttributes:attrsDictionary range:NSMakeRange(0,
[htmlLinkString length])];
--Nathan
_______________________________________________
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