July 10 2010
Cocoa Tip: URLs in NSTextFields
Apple has a great Technical Q&A document for embedding a URL in an NSTextField. However, after implementing their approach, I found two issues:
Font: When I clicked the link, the URL’s font changed. To keep it consistent, I needed to set it myself. I added the following code to Apple’s NSAttributedString category from the link above:
Cursor: With Apple’s code, the pointing hand cursor only appeared after I clicked the link. To get the correct cursor before the link is clicked, I followed the advice from a cocoa-dev post and subclassed NSTextField to override resetCursorRects.