Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTExtView



>
> 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 &nbsp; bold italic
&nbsp;</font><br>
<font face="Helvetica" size="3"></font><br>
<font face="Helvetica" size="3">a&lt;b.&nbsp;</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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >NSTExtView (From: email@hidden)
 >Re: NSTExtView (From: Jens Alfke <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.