IOS Rich Text and ios text
// NSFontAttributeName sets the font attribute. Default Value: Font: Helvetica (Neue) font size: 12 // NSForegroundColorAttributeNam sets the font color. The value is a UIColor object, the default value is black // NSBackgroundColorAttributeName. Set the background color of the font's region. The value is a UIColor object, the default value is nil, and the transparent color // NSLigatureAttributeName sets the connected property. The value is an integer of NSNumber ), 0 indicates that no conjoined characters exist. 1 indicates that the default conjoined characters are used. // NSKernAttributeName indicates the Character spacing. The value is an NSNumber object (integer), and the spacing of positive values is widened, the spacing of negative values is narrowed // The strikethrough is set. The value is an NSNumber object (integer) // NSStrikethroughColorAttributeName. The value is a UIColor object. The default value is black. // NSUnderlineStyleAttributeName, the value is an NSNumber object (integer), and the value in the enumerated constant NSUnderlineStyle is similar to the strikethrough. // set the underline color for NSUnderlineColorAttributeName and the value is a UIColor object. The default value is black. // NSStrokeWidthAttributeName, the value is an NSNumber object (integer), and the fill effect of negative values is positive. The fill color of NSStrokeColorAttributeName is not the font color. The value is a UIColor object. // NSShadowAttributeName, the value is NSShadow object // NSTextEffectAttributeName. The value is NSString. Currently, only the graphic printing effect is available: // NSBaselineOffsetAttributeName. The value is NSNumber (float ), positive Value top offset, negative value bottom offset // NSObliquenessAttributeName sets the font skew, value: NSNumber (float), positive value right tilt, negative value left tilt // NSExpansionAttributeName sets the text horizontal stretch attribute, set the value to NSNumber (float), positive value to horizontally stretch the text, and negative value to horizontally compress the text // nswritingdirectionbutbutename to set the text writing direction, write from left to right or from right to left // NSVerticalGlyphFormAttributeName sets the text layout direction. The value is an NSNumber object (integer) and 0 indicates horizontal text, 1 indicates that the link attribute is set in the vertical text // NSLinkAttributeName. After clicking it, call the browser to open the specified URL // NSAttachmentAttributeName to set the text attachment. The value is the NSTextAttachment object, it is often used for text image mixing. // NSParagraphStyleAttributeName is used to set the text section layout format. The value is an NSParagraphStyle object.
[Objc]View plain copy
- // Create a small text for testing
- UILabel * label = [[UILabel alloc] initWithFrame: [UIScreen mainScreen]. bounds];
- Label. font = [UIFont systemFontOfSize: 30];
- Label. textAlignment = NSTextAlignmentCenter;
- Label. numberOfLines = 0;
[Objc]View plain copy
- NSMutableAttributedString * attributedText = [[NSMutableAttributedString alloc] initWithString: @ "test text: \ n change text spacing \ n change text size \ n change text color \ n change text background \ n add text strikethrough \ n add Text underline \ n Set Font skew \ n set text flattening "];
- // Change the text spacing
- [AttributedText setAttributes: @ {NSKernAttributeName: @ 10} range: NSMakeRange (6, 6)];
- // Change the text size
- [AttributedText setAttributes: @ {NSFontAttributeName: [UIFont systemFontOfSize: 30]} range: NSMakeRange (13, 6)];
- // Change the text color
- [AttributedText setAttributes: @ {NSForegroundColorAttributeName: [UIColor redColor]} range: NSMakeRange (20, 6)];
- // Change the text color
- [AttributedText setAttributes: @ {NSBackgroundColorAttributeName: [UIColor yellowColor]} range: NSMakeRange (27, 6)];
- // Add a text strikethrough (NSUnderlineStyleSingle is an enumeration. Try it yourself in detail)
- [AttributedText setAttributes: @ {NSStrikethroughStyleAttributeName: @ (NSUnderlineStyleSingle)} range: NSMakeRange (34, 7)];
- // Add a Text underline (NSUnderlineStyleSingle is an enumeration. Try it yourself in detail)
- [AttributedText setAttributes: @ {NSUnderlineStyleAttributeName: @ (NSUnderlineStyleThick)} range: NSMakeRange (42, 7)];
- // Set Font skew
- [AttributedText setAttributes :@ {NSObliquenessAttributeName: @ 0.5} range: NSMakeRange (50, 6)];
- // Set text flattening
- [AttributedText setAttributes: @ {NSExpansionAttributeName: @ 0.4} range: NSMakeRange (57, 7)];
- // Bold font
- [AttributedText setAttribute: NSExpansionAttributeName value: @ (0.5) range: range];
- // Assign a value to the modified text
[Objc]View plain copy
- Label. attributedText = attributedText;
- [Self. view addSubview: label];
Official API reference link: valve http://blog.csdn.net/u010330109/article/details/51882122