Re: URL formatting in NSAttributedString
Re: URL formatting in NSAttributedString
- Subject: Re: URL formatting in NSAttributedString
- From: "Mark A. Stratman" <email@hidden>
- Date: Sat, 26 Jun 2004 02:40:52 -0500
I've never done it personally, but I recalled a discussion on the
cocoadev wiki.
http://cocoadev.com/index.pl?ClickableUrlInTextView
It has some sample code and a few tips from people who've done this
before. It might help out.
- mark
On Jun 26, 2004, at 1:50 AM, Rachel Blackman wrote:
So, I'm working away on a project in Cocoa, and enjoying myself
immensely, but now I've hit a rather irksome problem.
I want to scan for any http URLs in the given string -- no problem, I
can do that fine -- and mark them up with an NSURL in the
NSLinkAttributeName attribute. All this works fine, but here's the fun
part.
I cannot seem to set the cursor to anything other than the IBeam, nor
can I change the color away from blue. Both are highly desirable, but
neither works. If I remove the NSLinkAttributeName, the color (though
not the cursor) sets correctly. Am I overlooking something obvious (or
non-obvious?) in this?
Code is below... I added removeAttribute calls just in case I was
overlooking something, but that doesn't seem to do it either.
_rdLinkCursor and [world colorForLink] both are valid, also; I've
step-debugged to check that, and I'd see an exception raised anyway if
they were nil. finalString is returned and added to an NSTextView's
TextStorage. Everything else for formatting finalString works fine...
Help? :)
[finalString addAttribute:NSLinkAttributeName value:newURL
range:foundUrlRange];
[finalString addAttribute:NSUnderlineStyleAttributeName
value:[NSNumber numberWithInt:NSSingleUnderlineStyle]
range:foundUrlRange];
// Just for good measure...
[finalString
removeAttribute:NSForegroundColorAttributeName
range:foundUrlRange];
[finalString removeAttribute:NSCursorAttributeName
range:foundUrlRange];
[finalString addAttribute:NSCursorAttributeName
value:_rdLinkCursor range:foundUrlRange];
[finalString addAttribute:NSForegroundColorAttributeName
value:[world colorForLinks] range:foundUrlRange];
--
Rachel 'Sparks' Blackman -- sysadmin, developer, mad scientist
"If it is not broken, give me five minutes to redesign it!"
_______________________________________________
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.
_______________________________________________
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.