IOS Rich Text and ios text

Source: Internet
Author: User
Tags transparent color

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
  1. // Create a small text for testing
  2. UILabel * label = [[UILabel alloc] initWithFrame: [UIScreen mainScreen]. bounds];
  3. Label. font = [UIFont systemFontOfSize: 30];
  4. Label. textAlignment = NSTextAlignmentCenter;
  5. Label. numberOfLines = 0;
[Objc]View plain copy
  1. 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 "];
  2. // Change the text spacing
  3. [AttributedText setAttributes: @ {NSKernAttributeName: @ 10} range: NSMakeRange (6, 6)];
  4. // Change the text size
  5. [AttributedText setAttributes: @ {NSFontAttributeName: [UIFont systemFontOfSize: 30]} range: NSMakeRange (13, 6)];
  6. // Change the text color
  7. [AttributedText setAttributes: @ {NSForegroundColorAttributeName: [UIColor redColor]} range: NSMakeRange (20, 6)];
  8. // Change the text color
  9. [AttributedText setAttributes: @ {NSBackgroundColorAttributeName: [UIColor yellowColor]} range: NSMakeRange (27, 6)];
  10. // Add a text strikethrough (NSUnderlineStyleSingle is an enumeration. Try it yourself in detail)
  11. [AttributedText setAttributes: @ {NSStrikethroughStyleAttributeName: @ (NSUnderlineStyleSingle)} range: NSMakeRange (34, 7)];
  12. // Add a Text underline (NSUnderlineStyleSingle is an enumeration. Try it yourself in detail)
  13. [AttributedText setAttributes: @ {NSUnderlineStyleAttributeName: @ (NSUnderlineStyleThick)} range: NSMakeRange (42, 7)];
  14. // Set Font skew
  15. [AttributedText setAttributes :@ {NSObliquenessAttributeName: @ 0.5} range: NSMakeRange (50, 6)];
  16. // Set text flattening
  17. [AttributedText setAttributes: @ {NSExpansionAttributeName: @ 0.4} range: NSMakeRange (57, 7)];
  18. // Bold font
  19. [AttributedText setAttribute: NSExpansionAttributeName value: @ (0.5) range: range];
  20. // Assign a value to the modified text
[Objc]View plain copy
  1. Label. attributedText = attributedText;
  2. [Self. view addSubview: label];

Official API reference link: valve http://blog.csdn.net/u010330109/article/details/51882122

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.