• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTExtView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 &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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSTExtView
      • From: Jens Alfke <email@hidden>
References: 
 >NSTExtView (From: email@hidden)
 >Re: NSTExtView (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: NSControllers, NSLocks, NSThread, Setters and Getters
  • Next by Date: Re: DirWatch
  • Previous by thread: Re: NSTExtView
  • Next by thread: Re: NSTExtView
  • Index(es):
    • Date
    • Thread