• 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: Color of string with link attribute
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Color of string with link attribute


  • Subject: Re: Color of string with link attribute
  • From: Jeremy Dronfield <email@hidden>
  • Date: Fri, 18 Jun 2004 10:24:34 +0100

On 17 Jun 2004, at 5:43 pm, Douglas Davidson wrote:

On Jun 17, 2004, at 1:41 AM, Jeremy Dronfield wrote:

If you're coding for 10.3, you can subclass NSTextView and override -linkTextAttributes. Return an empty dictionary if you want the linked text to have whatever style attributes you dictate when you create the link, or return a dictionary containing the attributes you want all your links to have. Or a mixture of both. For example, I have an application which colour-codes hyperlinks according to whether they're file:, http: or local in-application links. The NSForegroundColorAttributeName is applied to the text when the link is created, and -linkTextAttributes returns [NSDictionary dictionaryWithObject:[NSCursor pointingHandCursor] forKey:NSCursorAttributeName], which is common to all hyperlinks.

No need to subclass--just call setLinkTextAttributes: with an appropriate dictionary.

You're right of course, and I should have mentioned that. I pulled this example out of one of my own applications, where I subclass a) because the text view gets reused in a number of different places in my UI; b) because it's already subclassed for other reasons, and c) because the user can switch hyperlink colour-coding on and off, and I find it more efficient to if/else in -linkTextAttributes to return either the set dictionary or {super linkTextAttributes] than to send -set from a number of different places.

Regards,

-Jeremy

===================================
SkoobySoft, home of viJournal
email: email@hidden or visit:
http://freespace.virgin.net/jeremy.dronfield/skoobysoft.html
===================================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Color of string with link attribute (From: Nils Hjelte <email@hidden>)
 >Re: Color of string with link attribute (From: Jeremy Dronfield <email@hidden>)
 >Re: Color of string with link attribute (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Re: Obj-C runtime not thread-safe?!
  • Next by Date: Re: Small resize control with textured (metal) window
  • Previous by thread: Re: Color of string with link attribute
  • Next by thread: cocoa.h not found?
  • Index(es):
    • Date
    • Thread