The AppKit framework offers several NSAttributedString additions that will help the developer inserting various objects in a NSTextView: | initWithHTML, initWithPath, initWithRTF, initWithRTFD, initWithURL, …
In this particluar case, we will use initWithHTML which takes an NSData argument to specify the HTML code to be inserted. NSString allowing easy conversion to a NSData object with dataUsingEncoding, we can write:
NSString *myHTMLString = @"my_url_here">my_label" ;
NSDate *myData = [myHTMLString dataUsingEncoding:NSUTF8StringEncoding];
NSAttributedString *textToBeInserted = [[[NSAttributedString alloc]
initWithHTML:myData documentAttributes:nil] autorelease];
See also Apple Sample Code
|