Re: How to create Hypertext in cocoa applications?
Re: How to create Hypertext in cocoa applications?
- Subject: Re: How to create Hypertext in cocoa applications?
- From: John Pannell <email@hidden>
- Date: Wed, 29 Aug 2007 06:54:38 -0600
Hi there-
Here is the code I use to make linked text - it uses an
NSMutableAttributedString and set the characteristics needed to make
the link appearance and the clickability.
NSString *normal = @"Click ";
NSString *link = @"here";
NSString *total = [NSString stringWithFormat:@"%@%@", normal,
link];
NSMutableAttributedString *newTitleString =
[[NSMutableAttributedString alloc] initWithString:total];
NSRange attrRange = NSMakeRange(([newTitleString length] - [link
length]), [link length]);
[newTitleString addAttribute:NSLinkAttributeName value:@"http://
www.mysite.com" range:attrRange];
[newTitleString addAttribute:NSForegroundColorAttributeName
value:[NSColor blueColor] range:attrRange];
[newTitleString addAttribute:NSUnderlineStyleAttributeName value:
[NSNumber numberWithInt:1] range:attrRange];
[newTitleString fixAttributesInRange:NSMakeRange(0,
[newTitleString length])];
At this point, you should be able to put newTitleString into your
table cell, and it should appear and function like a link.
Hope this helps!
John
On Aug 28, 2007, at 10:33 PM, Sachin Kumar Tulla wrote:
Hi,
I am developing an application in which NSTableView has a first
column with multiple cell type. Like first column in each row has
four strings and one icon. I need to develop such that two strings
should respond as hyperlink text, which should respond to an
actionMethod where as a normal button respond. So I need to know
how a text would be represented as an hypertext.
I could't able to represent a normal text in an textfield as a
hypertext, so thought of getting it normally n then implement in
the application.
Through help I have seen NSAttributedString and
NSHTMLTextDocumentType, but not able to.
_______________________________________________
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