Adding Links to Attributed String
Adding Links to Attributed String
- Subject: Adding Links to Attributed String
- From: "Erik J. Barzeski" <email@hidden>
- Date: Thu, 13 Jun 2002 12:38:28 -0400
Hi,
I've looked over Cocoa.mamasam.com and have not quite found the answer to
this. Perhaps something will turn up here.
I've got an RTFD file from which I read an attributed string:
NSMutableAttributedString *someString = [[NSMutableAttributedString alloc]
initWithPath:[[NSBundle mainBundle] pathForResource:@"SomeFile"
ofType:@"rtfd"] documentAttributes:nil];
From there I'd like to make some of the text clickable. I attempt to do this
like so:
NSMutableString *links = [someString mutableString];
[someString addAttribute:NSLinkAttributeName value:@"
http://www.myurl.com/"
range:[links rangeOfString:@"
http://www.myurl.com/"]];
This fails - nothing is clickable. NSLogging the range reveals what I would
expect are proper .location and .lengths.
I then replace the characters in a textview with the attributed string:
[someTextView replaceCharactersInRange:NSMakeRange(0, 0)
withRTFD:[someString RTFDFromRange: NSMakeRange(0, [someString length])
documentAttributes:nil]];
No errors (compile-time), but no clickable links either. Not quite sure
what's going on here.
I've also, of course, tried giving the value: an NSURL:
[someString addAttribute:NSLinkAttributeName value:[NSURL
URLWithString:@"
http://www.myurl.com/"] range:[links
rangeOfString:@"
http://www.myurl.com/"]];
The data is an RTFD because there is an image at the top. I've clicked all
around thinking I may be off by a little and can't seem to find the
clickable region anywhere.
I held off sending this email for two days while I did some research, but it
hasn't produced anything (plus I got distracted by the fact that Omni
frameworks don't compile or link properly in the April Dev Tools). I'm sure
it's something stupid... But I'm just not seeing it.
If someone can point me in the right place (I've looked at all the string
documentation I could think of...), I'd appreciate it.
--
Best wishes,
Erik J. Barzeski
If you don't know where you're going
You will probably not end up there.
*******************************************************************
Email: erik@(anything below)
AIM: iacas ICQ: 8186546
http://barzeski.com/ http://weims.net/
http://techstra.net/ http://cocoadevcentral.com/
http://soundsetcentral.com/ http://applescriptcentral.com/
*******************************************************************
_______________________________________________
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.