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:
- NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- ParagraphStyle. lineHeightMultiple = paif;
- ParagraphStyle. maximumLineHeight = 25.f;
- ParagraphStyle. minimumLineHeight = 15.f;
- ParagraphStyle. firstLineHeadIndent = paif;
- ParagraphStyle. alignment = NSTextAlignmentJustified;
- NSDictionary * attributes =@{ NSFontAttributeName: [UIFont systemFontOfSize: 14], NSParagraphStyleAttributeName: paragraphStyle, NSForegroundColorAttributeName: [UIColor colorWithRed: 76. /255. green: 75. /255. blue: 71. /255. alpha: 1]
- };
- 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.
- NSMutableAttributedString * recognition = [[NSMutableAttributedString alloc] initWithString: detail];
- [Maid: NSFontAttributeName value: [UIFont systemFontOfSize: 14] range: NSMakeRange (0, detail. length)];
- TextView. attributedText = recognition;
You can also customize the link style in textview.
- NSDictionary * linkAttributes =@{ NSForegroundColorAttributeName: [UIColor blueColor],
- NSUnderlineColorAttributeName: [UIColor blackColor],
- NSUnderlineStyleAttributeName: @ (NSUnderlinePatternDash )};
- Self. linkTextAttributes = linkAttributes;
This is just a simple example. For more information about attributes, see the header file.