Re: NSAttributedString has initWithHTML method
Re: NSAttributedString has initWithHTML method
- Subject: Re: NSAttributedString has initWithHTML method
- From: Darin Duphorne <email@hidden>
- Date: Thu, 24 Jan 2002 15:57:04 -0600
Thanks. That helped a lot. I knew I was missing something obvious. However,
with setAttributedStringValue: the text isn't displayed as rich. It strips
the html tags and displays the plain text only. I tried [textField recievesImages]
, hoping that would tell it that it would contain rich text and that didn'
t help. I also tried [textField setRichText:YES]; Any ideas?
On Wednesday, January 23, 2002, at 09:55 PM, Kurt Revis wrote:
On Wednesday, January 23, 2002, at 05:23 PM, Darin Duphorne wrote:
Wow! NSAttributedString Class Cluster Additions provides an initWithHTML
method to NSAttributedString.
Maybe this is the answer to my HTML Editor problem. But, can anyone tell
me why this crashes? It looks pretty straightforward.
@implementation controller
- (IBAction)doit:(id)sender
{
NSAttributedString *attrStr;
NSString *htmlString;
htmlString=@"<html><head></head><body><u>underlined </u><i>italics</i></body>
</html>";
[attrStr initWithHTML:[htmlString dataUsingEncoding:NSASCIIStringEncoding]
documentAttributes:NULL];
[textField lockFocus];
[attrStr drawAtPoint:NSMakePoint(0.0, 0.0)];
}
@end
You are not actually allocating the attributed string. This should be
attrStr = [[NSAttributedString alloc] initWithHTML:[htmlString dataUsingEncoding:
NSASCIIStringEncoding] documentAttributes:NULL];
As for the rest, it is a better idea to just set the text field to contain
the attributed string, and let it draw itself, rather than forcing it to
draw.
[textField setAttributedStringValue:attrStr];
Hope this helps.
--
Kurt Revis
email@hidden