Re: NSTExtView
Re: NSTExtView
- Subject: Re: NSTExtView
- From: email@hidden
- Date: Fri, 23 May 2008 00:34:10 -0400 (EDT)
- Importance: Normal
>
> On 22 May '08, at 8:42 PM, email@hidden wrote:
>
>> [str initWithString:[self messageField]];
>
> Well, that's the problem. You initialized the attributed string from a
> plain string, which means it gets no formatting.
>
> If your text is in an NSTextField, call -attributedStringValue on it
> to get the text with styles.
>
> Jens
I hope you could understand my question,
I've a Textview contains the string
"Sample mail bold italic
a<b.
Itdoesn't convert bold italic underline."
I can convert it to
<html>
<head>
<title>Sample</title>
</head>
<body>
<font face="Helvetica" size="3">Sample mail bold italic
</font><br>
<font face="Helvetica" size="3"></font><br>
<font face="Helvetica" size="3">a<b. </font><br>
<font face="Helvetica" size="3"></font><br>
<font face="Helvetica" size="3">Itdoesn't convert bold italic
underline.</font>
</body>
</html>
by using the code
NSAttributedString * str = [[NSAttributedString alloc]init];
[str initWithString:[self messageField]];//where messageField gives string.
NSString * aTitle = @"Sample";
NSArray* excluded = [NSArray arrayWithObjects:
@"doctype",@"p",@"meta",@"xml",@"span", nil];
NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys:
NSHTMLTextDocumentType,
NSDocumentTypeDocumentAttribute,
aTitle, NSTitleDocumentAttribute,excluded,
NSExcludedElementsDocumentAttribute,
[NSNumber numberWithInt: NSASCIIStringEncoding],
NSCharacterEncodingDocumentAttribute,nil];
NSData* tData = [str dataFromRange: NSMakeRange(0, [str length])
documentAttributes: attr error: nil];
NSString * fileContents=[[NSString alloc] initWithData:tData
encoding:NSNEXTSTEPStringEncoding];
[htmlView setString:fileContents];//htmlView is textview.
but doesnot gives <b>,<i> or colour tags corresponding to the values.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden