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=\"[EMAIL PROTECTED]">%@</a>", self.sourceProjectURL, self.sourceProjectURL] dataUsingEncoding: NSUTF8StringEncoding] documentAttributes: nil];

[htmlLinkString addAttributes:attrsDictionary range:NSMakeRange(0, [htmlLinkString length])];


--Nathan
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to