ios学习--NSAttributedString用法 & NSMutableParagraphStyle 来创建多姿多彩的文本

来源:互联网 发布:php无限层级数据拼接 编辑:程序博客网 时间:2024/06/06 03:57

  对多段文本定制特定一部分文字和段落的特色可能是很多菜鸟的难言之隐,一个label、两个label、。。。一万个label,sorry 内存溢出,game over!

  so,让我们一起学习一下:

  首先,来看一段代码:

        

self.contentTextView = [[UITextView alloc]init];

    float contentTextView_X = nameLabel_X;

    float contentTextView_Y = nameLabel_Y + nameLabel_HEIGHT;

    float contentTextView_WIDTH = detailView_WIDTH - contentTextView_X*2;

    float contentTextView_HEIGHT = detailView_HEIGHT - contentTextView_Y;

    [self.contentTextView setFrame:CGRectMake(contentTextView_X, contentTextView_Y, contentTextView_WIDTH, contentTextView_HEIGHT)];

    [self.contentTextViewsetText:@"      橘色的短发(两年后为波浪长发)和左肩的刺青(风车与橘子的图案)。使用棍术,现在武器为魔法天候棒。头脑聪明又机灵,精通气象学和航海术,擅长偷术,能用身体感知天气,完美指示航路,是个能精确画出航海图的天才航海士。本质上是个细心、善良、重视感情、嫉恶如仇、偶尔有些温柔的能干的女性。最喜欢钱和橘子,梦想是要画出全世界的地图。\n       爱短发,也爱波浪长发,精通气象学和航海术,擅长威胁恐吓,也头脑聪明,偶尔温柔,同时嫉恶如仇,梦想要画出全世界的地图,我就是人见人爱的草帽海贼团航海士--------------------------------小贼猫娜美"];

    [self.contentTextView setContentSize:CGSizeMake(contentTextView_WIDTH, contentTextView_HEIGHT)];

    [self.contentTextView setFont:[UIFont fontWithName:@"Georgia-Italic" size:16]];

    

    [self.contentTextView setTextColor:[UIColor redColor]];

    [self.contentTextView setEditable:NO];

    [self.detailView addSubview:self.contentTextView];

    


    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];

    paragraphStyle.lineSpacing = 5;

    NSDictionary *atttibutes = @{

                                 NSFontAttributeName:[UIFont fontWithName:@"Georgia-Italic" size:16],

                                 NSParagraphStyleAttributeName:paragraphStyle

                                 };

    self.contentTextView.attributedText = [[NSAttributedString alloc]initWithString:self.contentTextView.text attributes:atttibutes];



可见,使用NSAttributedString,也就是富文本,对文本内容进行了重新排版。

下面我们就认识一下其常见的属性和都能实现什么定制项:

NSAttributedString叫做富文本,是一种带有属性的字符串,通过它可以轻松的在一个字符串中表现出多种字体、字号、字体大小等各不相同的风格,还可以对段落进行格式化。


-------NSMutableAttributedString-------

NSAttributedString对象在创建成功后其属性便不可改变,而NSMutableAttributedString的属性是可以改变的。如下所示:

// Change NSMutableAttributedString   2 [mutableAttributedString_attrs beginEditing];   3 /*  4 // addAttributes:range:  5 [mutableAttributedString_attrs addAttributes:@{NSLinkAttributeName: @"www.baidu.com",  6                                                NSBackgroundColorAttributeName: [UIColor greenColor],  7                                                NSUnderlineStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleDouble]  8                                                }  9                                        range:NSMakeRange(0, [attributedString_fileURL length])]; */  10 // addAttribute:value:range:  11 [mutableAttributedString_attrs addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleThick] range:NSMakeRange(0, 10)];  12 [mutableAttributedString_attrs addAttribute:NSBaselineOffsetAttributeName value:[NSNumber numberWithFloat:20.0] range:NSMakeRange(20, 100)];  13 [mutableAttributedString_attrs endEditing];  14 NSLog(@"%@", mutableAttributedString_attrs);  
在修改文字属性的开头和结尾要分别调用beginEditing和endEditing方法,这些方法可以在文字属性发生变化时发送消息给事件监听者。

--------------

常用属性:

NSFontAttributeName           文字字体

NSParagraphStyleAttributeName     段落样式(字符串通过“\n”进行分段,此设置必须在lable.numberOfLines = 0时有效,value通过NSMutableParagraphStyle设置,它有以下属性)

/*--------NSMutableParagraphStyle----

@property(readwrite) CGFloat lineSpacing;              //行间距 2 @property(readwrite) CGFloat paragraphSpacing;           //段间距 3 @property(readwrite) NSTextAlignment alignment;           //对齐方式 4 @property(readwrite) CGFloat firstLineHeadIndent;          //首行缩紧 5 @property(readwrite) CGFloat headIndent;               //除首行之外其他行缩进(尾部缩进 6 @property(readwrite) CGFloat tailIndent;               //每行容纳字符的宽度 7 @property(readwrite) NSLineBreakMode lineBreakMode;         //换行方式 8 @property(readwrite) CGFloat minimumLineHeight;           //最小行高 9 @property(readwrite) CGFloat maximumLineHeight;           //最大行高10 @property(readwrite) NSWritingDirection baseWritingDirection;  //书写方式(NSWritingDirectionNaturalNSWritingDirectionLeftToRightNSWritingDirectionRightToLeft
11 @property(readwrite) CGFloat lineHeightMultiple; //可变行高,乘因数
12 @property(readwrite) CGFloat paragraphSpacingBefore; //段首空间
13 @property(readwrite) float hyphenationFactor;  //连字符属性
14 @property(readwrite,copy,NS_NONATOMIC_IOSONLY) NSArray *tabStops NS_AVAILABLE_IOS(7_0);
15 @property(readwrite,NS_NONATOMIC_IOSONLY) CGFloat defaultTabInterval NS_AVAILABLE_IOS(7_0);

*/


基本属性:

NSForegroundColorAttributeName    文字前景色

NSBackgroundColorAttributeName     文字背景色

NSLigatureAttributeName        连体字(NSNumber  @0:无连体,@1:默认连体,系统字体不包含对连体的支持)

NSUnderlineStyleAttributeName     下划线

NSStrokeColorAttributeName       只有在NSStrokeWidthAttributeName设置了值之后才有效(默认字体颜色和前景色一致,如果设置的颜色和前景色不一致则前景色无效)

NSStrokeWidthAttributeName      设置该属性之后字体变成空心字体,字体边线宽度为value设定的值

NSBaselineOffsetAttributeName     值为NSNumber类型,表明文字相对于其他文字基准线向上的偏移量

NSUnderlineColorAttributeName      值为UIColor类型,下划线颜色(只有在NSUnderlineStyleAttributeName的value为@1时有效)

NSUnderlineStyleAttributeName      值为NSNumber类型,下划线宽度(默认值为@0:下划线宽度为0——不现实下划线,@1:字符串有下划线)

NSShadowAttributeName                                          值为NSShadow,设置比画的阴影,默认值为nil

NSVerticalGlyphFormAttributeName                          值为整型NSNumber,0为水平排版的字,1为垂直排版的字

NSKernAttributeName                                                值为浮点数NSNumber,字距属性,默认值为0

NSStrikethroughStyleAttributeName                           值为整型NSNumber,设置删除线,可取值为

enum {

NSUnderlineStyleNone = 0×00,

NSUnderlineStyleSingle = 0×01,

};设置删除线



根据以上基本属性,NSAttributedString也可以分别设置指定范围的文本的样式:

NSString * aString = @"¥150 元/位";          //富文本对象     NSMutableAttributedString * aAttributedString = [[NSMutableAttributedString alloc] initWithString:aString];          //富文本样式     [aAttributedString addAttribute:NSForegroundColorAttributeName  //文字颜色                               value:[UIColor redColor]                               range:NSMakeRange(0, 4)];         [aAttributedString addAttribute:NSFontAttributeName             //文字字体                              value:[UIFont systemFontOfSize:25]                               range:NSMakeRange(0, 4)];


ps:下面为转载自http://blog.csdn.net/mengxiangyue/article/details/46526297,特此声明:

  1. //  
  2. //  NSAttributedString.h  
  3. //  UIKit  
  4. //  
  5. //  Copyright (c) 2011-2014 Apple Inc. All rights reserved.  
  6. //  
  7.   
  8. #import <Foundation/Foundation.h>  
  9. #import <UIKit/UIKitDefines.h>  
  10.   
  11. /************************ Attributes ************************/  
  12.   
  13. /* Predefined character attributes for text. If the key is not in the dictionary, then use the default values as described below. 
  14.  * 预定义的text的字符属性,如果这个key没有在设置的Dictionary中,将会使用下面介绍的。 
  15.  */  
  16. // 字体  
  17. UIKIT_EXTERN NSString *const NSFontAttributeName NS_AVAILABLE_IOS(6_0);                // UIFont, default Helvetica(Neue) 12  
  18. // 段落样式  
  19. UIKIT_EXTERN NSString *const NSParagraphStyleAttributeName NS_AVAILABLE_IOS(6_0);      // NSParagraphStyle, default defaultParagraphStyle  
  20. // 文字颜色  
  21. UIKIT_EXTERN NSString *const NSForegroundColorAttributeName NS_AVAILABLE_IOS(6_0);     // UIColor, default blackColor  
  22. // 文字背景颜色  
  23. UIKIT_EXTERN NSString *const NSBackgroundColorAttributeName NS_AVAILABLE_IOS(6_0);     // UIColor, default nil: no background  
  24. // 设置连体属性,取值为NSNumber 对象(整数),0 表示没有连体字符,1 表示使用默认的连体字符  
  25. UIKIT_EXTERN NSString *const NSLigatureAttributeName NS_AVAILABLE_IOS(6_0);            // NSNumber containing integer, default 1: default ligatures, 0: no ligatures  
  26. // 设定字符间距  
  27. UIKIT_EXTERN NSString *const NSKernAttributeName NS_AVAILABLE_IOS(6_0);                // NSNumber containing floating point value, in points; amount to modify default kerning. 0 means kerning is disabled.  
  28. // 设置删除线  
  29. UIKIT_EXTERN NSString *const NSStrikethroughStyleAttributeName NS_AVAILABLE_IOS(6_0);  // NSNumber containing integer, default 0: no strikethrough  
  30. // 下划线  
  31. UIKIT_EXTERN NSString *const NSUnderlineStyleAttributeName NS_AVAILABLE_IOS(6_0);      // NSNumber containing integer, default 0: no underline  
  32. // 填充部分颜色 same as foreground color  
  33. UIKIT_EXTERN NSString *const NSStrokeColorAttributeName NS_AVAILABLE_IOS(6_0);         // UIColor, default nil: same as foreground color  
  34. // 设置笔画宽度  
  35. UIKIT_EXTERN NSString *const NSStrokeWidthAttributeName NS_AVAILABLE_IOS(6_0);         // NSNumber containing floating point value, in percent of font point size, default 0: no stroke; positive for stroke alone, negative for stroke and fill (a typical value for outlined text would be 3.0)  
  36. // 阴影属性  
  37. UIKIT_EXTERN NSString *const NSShadowAttributeName NS_AVAILABLE_IOS(6_0);              // NSShadow, default nil: no shadow  
  38. // 文本特殊效果  
  39. UIKIT_EXTERN NSString *const NSTextEffectAttributeName NS_AVAILABLE_IOS(7_0);          // NSString, default nil: no text effect  
  40.   
  41. // 文本附件,取值为NSTextAttachment对象,常用于文字图片混排  
  42. UIKIT_EXTERN NSString *const NSAttachmentAttributeName NS_AVAILABLE_IOS(7_0);          // NSTextAttachment, default nil  
  43. // 设置链接属性,点击后调用浏览器打开指定URL地址  
  44. UIKIT_EXTERN NSString *const NSLinkAttributeName NS_AVAILABLE_IOS(7_0);                // NSURL (preferred) or NSString  
  45. UIKIT_EXTERN NSString *const NSBaselineOffsetAttributeName NS_AVAILABLE_IOS(7_0);      // NSNumber containing floating point value, in points; offset from baseline, default 0  
  46. // 设置基线偏移值,取值为 NSNumber (float),正值上偏,负值下偏  
  47. UIKIT_EXTERN NSString *const NSUnderlineColorAttributeName NS_AVAILABLE_IOS(7_0);      // UIColor, default nil: same as foreground color  
  48. // 设置删除线颜色,取值为 UIColor 对象,默认值为黑色  
  49. UIKIT_EXTERN NSString *const NSStrikethroughColorAttributeName NS_AVAILABLE_IOS(7_0);  // UIColor, default nil: same as foreground color  
  50. // 设置字形倾斜度,取值为 NSNumber (float),正值右倾,负值左倾  
  51. UIKIT_EXTERN NSString *const NSObliquenessAttributeName NS_AVAILABLE_IOS(7_0);         // NSNumber containing floating point value; skew to be applied to glyphs, default 0: no skew  
  52. // 设置文本横向拉伸属性,取值为 NSNumber (float),正值横向拉伸文本,负值横向压缩文本  
  53. UIKIT_EXTERN NSString *const NSExpansionAttributeName NS_AVAILABLE_IOS(7_0);           // NSNumber containing floating point value; log of expansion factor to be applied to glyphs, default 0: no expansion  
  54.   
  55. // 设置文字书写方向,从左向右书写或者从右向左书写  
  56. UIKIT_EXTERN NSString *const NSWritingDirectionAttributeName NS_AVAILABLE_IOS(7_0);    // NSArray of NSNumbers representing the nested levels of writing direction overrides as defined by Unicode LRE, RLE, LRO, and RLO characters.  The control characters can be obtained by masking NSWritingDirection and NSTextWritingDirection values.  LRE: NSWritingDirectionLeftToRight|NSTextWritingDirectionEmbedding, RLE: NSWritingDirectionRightToLeft|NSTextWritingDirectionEmbedding, LRO: NSWritingDirectionLeftToRight|NSTextWritingDirectionOverride, RLO: NSWritingDirectionRightToLeft|NSTextWritingDirectionOverride,  
  57.   
  58. // 设置文字排版方向,取值为 NSNumber 对象(整数),0 表示横排文本,1 表示竖排文本  
  59. UIKIT_EXTERN NSString *const NSVerticalGlyphFormAttributeName NS_AVAILABLE_IOS(6_0);   // An NSNumber containing an integer value.  0 means horizontal text.  1 indicates vertical text.  If not specified, it could follow higher-level vertical orientation settings.  Currently on iOS, it's always horizontal.  The behavior for any other value is undefined.  
  60.   
  61. /* This defines currently supported values for NSUnderlineStyleAttributeName and NSStrikethroughStyleAttributeName. 
  62.  * 下面定义了下划线、删除线支持的样式 
  63.  */  
  64. typedef NS_ENUM(NSInteger, NSUnderlineStyle) {  
  65.     NSUnderlineStyleNone                                = 0x00,   // 不设置下划线  
  66.     NSUnderlineStyleSingle                              = 0x01,   // 设置删除线为细单实线  
  67.     NSUnderlineStyleThick NS_ENUM_AVAILABLE_IOS(7_0)    = 0x02,   // 设置删除线为粗单实线  
  68.     NSUnderlineStyleDouble NS_ENUM_AVAILABLE_IOS(7_0)   = 0x09,   // 设置删除线为细双实线  
  69.   
  70.     // http://blog.csdn.net/harvic880925/article/details/9028823 参考  
  71.     NSUnderlinePatternSolid NS_ENUM_AVAILABLE_IOS(7_0)      = 0x0000,  // 实线  
  72.     NSUnderlinePatternDot NS_ENUM_AVAILABLE_IOS(7_0)        = 0x0100,  // 点线  
  73.     NSUnderlinePatternDash NS_ENUM_AVAILABLE_IOS(7_0)       = 0x0200,  // 虚线  
  74.     NSUnderlinePatternDashDot NS_ENUM_AVAILABLE_IOS(7_0)    = 0x0300,  
  75.     NSUnderlinePatternDashDotDot NS_ENUM_AVAILABLE_IOS(7_0) = 0x0400,  
  76.   
  77.     NSUnderlineByWord NS_ENUM_AVAILABLE_IOS(7_0) = 0x8000  
  78. } NS_ENUM_AVAILABLE_IOS(6_0);  
  79.   
  80. /* NSTextWritingDirection values used by NSWritingDirectionAttributeName. Can specify the formatting controls defined by Unicode Bidirectional Algorithm. 
  81.  */  
  82. typedef NS_ENUM(NSInteger, NSTextWritingDirection) {  
  83.     NSTextWritingDirectionEmbedding     = (0 << 1),  
  84.     NSTextWritingDirectionOverride      = (1 << 1)  
  85. } NS_ENUM_AVAILABLE_IOS(7_0);  
  86.   
  87. /* This defines the currently supported value for NSTextEffectAttributeName as of iOS 7.0 
  88.  */  
  89. UIKIT_EXTERN NSString *const NSTextEffectLetterpressStyle NS_AVAILABLE_IOS(7_0);  
  90.   
  91. /************************ Attribute fixing ************************/  
  92.   
  93. @interface NSMutableAttributedString (NSMutableAttributedStringKitAdditions)  
  94. // This method fixes attribute inconsistencies inside range.  It ensures NSFontAttributeName covers the characters, NSParagraphStyleAttributeName is only changing at paragraph boundaries, and NSTextAttachmentAttributeName is assigned to NSTextAttachmentCharacter.  NSTextStorage automatically invokes this method via -ensureAttributesAreFixedInRange:.  
  95. - (void)fixAttributesInRange:(NSRange)range NS_AVAILABLE_IOS(7_0);  
  96.   
  97. @end  
  98.   
  99.   
  100. /************************ Document formats ************************/  
  101.   
  102. // Supported document types for the NSDocumentTypeDocumentAttribute key in the document attributes dictionary.  
  103. UIKIT_EXTERN NSString *const NSPlainTextDocumentType NS_AVAILABLE_IOS(7_0); // 普通文本  
  104. UIKIT_EXTERN NSString *const NSRTFTextDocumentType NS_AVAILABLE_IOS(7_0);  
  105. UIKIT_EXTERN NSString *const NSRTFDTextDocumentType NS_AVAILABLE_IOS(7_0);  
  106. UIKIT_EXTERN NSString *const NSHTMLTextDocumentType NS_AVAILABLE_IOS(7_0);  // HTML  
  107.   
  108.   
  109. // Keys for NSLayoutOrientationSectionsAttribute.  
  110. // 文字展示的方向  
  111. UIKIT_EXTERN NSString *const NSTextLayoutSectionOrientation NS_AVAILABLE_IOS(7_0); // NSNumber containing NSTextLayoutOrientation value. default: NSTextLayoutOrientationHorizontal  
  112. // 字符的范围  
  113. UIKIT_EXTERN NSString *const NSTextLayoutSectionRange NS_AVAILABLE_IOS(7_0); // NSValue containing NSRange representing a character range. default: a range covering the whole document  
  114.   
  115.   
  116. // Keys for options and document attributes dictionaries.  They are in and out document properties used by both read/write methods.  
  117.   
  118. UIKIT_EXTERN NSString *const NSDocumentTypeDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"DocumentType", one of the document types declared above.  For reader methods, this key in options can specify the document type for interpreting the contents.  Upon return, the document attributes can contain this key for indicating the actual format used to read the contents.  For write methods, this key specifies the format for generating the data.  
  119.   
  120.   
  121. // NSPlainTextDocumentType document attributes  
  122. // 普通文本的编码  
  123. UIKIT_EXTERN NSString *const NSCharacterEncodingDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"CharacterEncoding", NSNumber containing integer specifying NSStringEncoding for the file; default for plain text is the default encoding.  This key in options can specify the string encoding for reading the data.  Upon return, the document attributes can contain the actual encoding used.  For writing methods, this value is used for generating the plain text data.  
  124. UIKIT_EXTERN NSString *const NSDefaultAttributesDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"DefaultAttributes", NSDictionary containing attributes to be applied to plain files.  Used by reader methods.  This key in options can specify the default attributes applied to the entire document contents.  The document attributes can contain this key indicating the actual attributes used.  
  125.   
  126.   
  127. // NSRTFTextDocumentType and NSRTFDTextDocumentType document attributes  
  128. // Document dimension  
  129. // They are document attributes used by read/write methods.  
  130. UIKIT_EXTERN NSString *const NSPaperSizeDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"PaperSize", NSValue containing CGSize (in points)  
  131. UIKIT_EXTERN NSString *const NSPaperMarginDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"PaperMargin", NSValue containing UIEdgeInsets  
  132.   
  133. UIKIT_EXTERN NSString *const NSViewSizeDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"ViewSize", NSValue containing CGSize (in points)  
  134. UIKIT_EXTERN NSString *const NSViewZoomDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"ViewZoom", NSNumber containing floating point value (100 == 100% zoom)  
  135. UIKIT_EXTERN NSString *const NSViewModeDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"ViewMode", NSNumber containing integer; 0 = normal; 1 = page layout  
  136.   
  137. // Document settings  
  138. // They are document attributes used by read/write methods.  
  139. UIKIT_EXTERN NSString *const NSReadOnlyDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"ReadOnly", NSNumber containing integer; if missing, or 0 or negative, not readonly; 1 or more, readonly. Note that this has nothing to do with the file system protection on the file, but instead, on how the file should be displayed to the user  
  140. UIKIT_EXTERN NSString *const NSBackgroundColorDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"BackgroundColor", UIColor, representing the document-wide page background color  
  141. UIKIT_EXTERN NSString *const NSHyphenationFactorDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"HyphenationFactor", NSNumber containing floating point value (0=off, 1=full hyphenation)  
  142. UIKIT_EXTERN NSString *const NSDefaultTabIntervalDocumentAttribute NS_AVAILABLE_IOS(7_0);  // @"DefaultTabInterval", NSNumber containing floating point value, representing the document-wide default tab stop interval, in points  
  143. UIKIT_EXTERN NSString *const NSTextLayoutSectionsAttribute NS_AVAILABLE_IOS(7_0);  // NSArray of dictionaries.  Each dictionary describing a layout orientation section.  The dictionary can have two attributes: NSTextLayoutSectionOrientation and NSTextLayoutSectionRange.  When there is a gap between sections, it's assumed to have NSTextLayoutOrientationHorizontal.  
  144.   
  145.   
  146. @interface NSAttributedString (NSAttributedStringDocumentFormats)  
  147. // Methods initializing the receiver contents with an external document data.  options specify document attributes for interpreting the document contents.  NSDocumentTypeDocumentAttribute, NSCharacterEncodingDocumentAttribute, and NSDefaultAttributesDocumentAttribute are supported options key.  When they are not specified, these methods will examine the data and do their best to detect the appropriate attributes.  If dict is non-NULL, it will return a dictionary with various document-wide attributes accessible via NS...DocumentAttribute keys.  
  148. - (instancetype)initWithFileURL:(NSURL *)url options:(NSDictionary *)options documentAttributes:(NSDictionary **)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);  
  149. - (instancetype)initWithData:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary **)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);  
  150.   
  151. // Generates an NSData object for the receiver contents in range.  It requires a document attributes dict specifying at least the NSDocumentTypeDocumentAttribute to determine the format to be written.  
  152. - (NSData *)dataFromRange:(NSRange)range documentAttributes:(NSDictionary *)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);  
  153.   
  154. // Returns an NSFileWrapper object for the receiver contents in range.  It requires a document attributes dict specifying at least the NSDocumentTypeDocumentAttribute to determine the format to be written.  The method returns a directory file wrapper for those document types represented by a file package such as NSRTFDTextDocumentType; otherwise, it returns a regular-file file wrapper.  
  155. - (NSFileWrapper *)fileWrapperFromRange:(NSRange)range documentAttributes:(NSDictionary *)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);  
  156.   
  157. @end  
  158.   
  159. @interface NSMutableAttributedString (NSMutableAttributedStringDocumentFormats)  
  160. // Methods replacing the receiver contents with an external document data.  options specify document attributes for interpreting the document contents.  NSDocumentTypeDocumentAttribute, NSCharacterEncodingDocumentAttribute, and NSDefaultAttributesDocumentAttribute are supported options key.  When they are not specified, these methods will examine the data and do their best to detect the appropriate attributes.  If dict is non-NULL, it will return a dictionary with various document-wide attributes accessible via NS...DocumentAttribute keys.  
  161. - (BOOL)readFromFileURL:(NSURL *)url options:(NSDictionary *)opts documentAttributes:(NSDictionary **)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);  
  162. - (BOOL)readFromData:(NSData *)data options:(NSDictionary *)opts documentAttributes:(NSDictionary **)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);  
  163. @end  


0 0
原创粉丝点击