IOS: personalized UITextView (indent, line spacing, full)

Source: Internet
Author: User

In general, there are two methods to customize UITextView content:

1. Read the content from the file to UITextView. This person feels that the rtfd and rtf files are very effective.

2. Use NSAttributeString for customization

The specific method is as follows:

  1. NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  2. ParagraphStyle. lineHeightMultiple = paif;
  3. ParagraphStyle. maximumLineHeight = 25.f;
  4. ParagraphStyle. minimumLineHeight = 15.f;
  5. ParagraphStyle. firstLineHeadIndent = paif;
  6. ParagraphStyle. alignment = NSTextAlignmentJustified;
  7. NSDictionary * attributes =@{ NSFontAttributeName: [UIFont systemFontOfSize: 14], NSParagraphStyleAttributeName: paragraphStyle, NSForegroundColorAttributeName: [UIColor colorWithRed: 76. /255. green: 75. /255. blue: 71. /255. alpha: 1]
  8. };
  9. TextView. attributedText = [[NSAttributedString alloc] initWithString: content attributes: attributes];

 

Of course, you can also Initialize an NSMutableAttributedString, add a text style to it, and assign it to the AttributedText of textView.

  1. NSMutableAttributedString * recognition = [[NSMutableAttributedString alloc] initWithString: detail];
  2. [Maid: NSFontAttributeName value: [UIFont systemFontOfSize: 14] range: NSMakeRange (0, detail. length)];
  3. TextView. attributedText = recognition;

 

You can also customize the link style in textview.

  1. NSDictionary * linkAttributes =@{ NSForegroundColorAttributeName: [UIColor blueColor],
  2. NSUnderlineColorAttributeName: [UIColor blackColor],
  3. NSUnderlineStyleAttributeName: @ (NSUnderlinePatternDash )};
  4. Self. linkTextAttributes = linkAttributes;

 

This is just a simple example. For more information about attributes, see the header file.

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.