-2

I am changing the font of textview, after I get attributed string then I use to pass it to another controller which also shows me attributed string. I would like to convert attributed string to NSString (with specific font which I have changed).

I am using

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:text.attributedText];
NSAttributedString *nas = [[NSAttributedString alloc] initWithData:data
                                                           options:nil
                                                documentAttributes:NULL
                                                             error:NULL];

NSString *str = [nas string];

Which shows below log:

2014-11-17 14:23:17.094 format[2785:98416] bplist00‘°¢T$topX$objectsX$versionY$archiver—TrootÄØ"    
%&'().6EFJRSTU[`glt}~ÅâäãåíñúU$null‘
XNSString\NSAttributesV$class_NSAttributeInfoÄÄÄ!ÄYThud high“
ZNS.objectsÄ¢ÄÄ”
 !WNS.keys£ÄÄ   ÄÄ£"#$ÄÄÄ[NSUnderline_NSParagraphStyleVNSFont”
*+,-(ZNSTabStops_NSWritingDirectionÄ
Ä
Kampai
  • 22,848
  • 21
  • 95
  • 95
  • Check this out: http://stackoverflow.com/questions/9018292/transform-an-nsattributedstring-to-plain-text – F1ank3r Nov 17 '14 at 08:47

3 Answers3

1

Actually NSAttributedString has string property:

NSString *result = myAttributedString.string;
B.S.
  • 21,660
  • 14
  • 87
  • 109
1

Just write

[attributedString string];
Rameswar Prasad
  • 1,331
  • 17
  • 35
0

You can covert attributed string to string using following line of code :

self.txtView.text = [attributedstring string];

but I suggest its better use as attribute text like below :

self.txtView.attributedText = attributedstring;
Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45