• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to create Hypertext in cocoa applications?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >How to create Hypertext in cocoa applications? (From: Sachin Kumar Tulla <email@hidden>)
 >Re: How to create Hypertext in cocoa applications? (From: Sachin Kumar Tulla <email@hidden>)

  • Prev by Date: radio buttons in NSMatrix obscuring text field
  • Next by Date: Re: NSXMLDocument freezes UI
  • Previous by thread: Re: How to create Hypertext in cocoa applications?
  • Next by thread: Distributed objects + timeouts
  • Index(es):
    • Date
    • Thread