***Attribut Rich text ***

stay UITextView and UILable Rich text is often used in the use of .

UITextView and UILable The difference is that :

****UITextView When the text is larger than a certain amount, you can scroll up and down
****UILable You can set long `Lalbe.number = 0` To set the line wrap , But when the text is larger than its full size, there will be endless text display .

NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:str];
// Format adjustment
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
/** Adjustment spacing */
style.lineSpacing = 10;

// Space between words
[attStr addAttribute:NSKernAttributeName value:@5 range:NSMakeRange(0, [str length])];
// Add row spacing
[attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, [str length])];

// Horizontal and vertical typesetting --- No effect
// [attStr addAttribute:NSVerticalGlyphFormAttributeName value:@1 range:NSMakeRange(0, [str length])];
// Draw the line down
[attStr addAttribute:NSUnderlineStyleAttributeName value:@1 range:NSMakeRange(0, [str length])];
// The width of the sideline
[attStr addAttribute:NSStrokeWidthAttributeName value:@1 range:NSMakeRange(10, 10)];
// Edge color
[attStr addAttribute:NSStrokeColorAttributeName value:[UIColor redColor] range:NSMakeRange(10, 10)];

// shadow -- No effect
[attStr addAttribute:NSShadowAttributeName value:@4 range:NSMakeRange(20, 10)];

// Underline
[attStr addAttribute:NSStrikethroughStyleAttributeName value:@2 range:NSMakeRange(20, 10)];
[attStr addAttribute:NSStrikethroughColorAttributeName value:[UIColor redColor] range:NSMakeRange(20, 10)];

// Font back color
[attStr addAttribute:NSBackgroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(45, 10)];

// The font color
[attStr addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(60, 10)];

// The paragraph -- No use
[attStr addAttribute:NSParagraphStyleAttributeName value:@6 range:NSMakeRange(70, 80)];

Lable Word spacing settings

 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.infoLabel.text attributes:@{NSKernAttributeName : @(2.5f)}];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(, self.infoLabel.text.length)];
[self.infoLabel setAttributedText:attributedString]; self.infoLabel.numberOfLines = ;
[self.infoLabel sizeToFit];
[self.scrollView addSubview:self.infoLabel];

Please refer to :

 NSString *strP = self.contentTextView.text;
// Remove space :"\t\t"
NSString *str = [strP stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
// Create rich text
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:str]; // Format adjustment
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; // Space between words
[attStr addAttribute:NSKernAttributeName value:@1.5f range:NSMakeRange(, [str length])]; // Font settings
[attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:RHFixXFlaot()] range:NSMakeRange(, [str length])]; // Line breaks
style.lineSpacing = ; // The paragraph
[attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(, [str length])]; // Indent the first line of the paragraph
style.firstLineHeadIndent = ; self.contentTextView.attributedText = attStr;

Please refer to [DEMO download ](https://github.com/marlonxlj/Attributing_Demo.git), More ways to use it need you to try it yourself .

Welcome to this article , If there are mistakes , Please point out that I can make adjustments in time , thank you . If it helps you, please go to the top right corner Star!

PS:

Attribute More articles on how to use rich text

  1. Wechat applet shows html Rich text approach

    Wechat applet shows html Rich text approach Usage method :git Address :https://github.com/icindy/wxParse One . download wxParse file Two . On the page to be introduced js In file , The introduction of the file j ...

  2. UILabel and UIbutton( Rich text ) Encapsulation method

    /** Method statement : Set up label Rich text properties of Parameter description :contentStr Rich text content textColor The font color rangeSet Set the position of font color and size */ - (UILabel *)backf ...

  3. Easy to use UILabel The rich text of

    Easy to use UILabel The rich text of Use effect : Source code : NSString+YX.h    NSString+YX.m // // NSString+YX.h // YXKit // // Copyrigh ...

  4. JAVA Integrate Ueditor Baidu rich text editor

    development environment : A simple SpringMVC In the frame , With Baidu rich text editor ueditor Upload pictures and files Official website address :http://ueditor.baidu.com/website/ Need to use 2 Individual article ...

  5. C#Winform Use the extended method to customize the rich text box (RichTextBox) The font color

    Using C# Development Winform When it comes to applications , It's possible for us to use RichTextBox To realize the function of displaying application log in real time , Logs are divided into : General news , Warning tips And errors . In order to better distinguish different types of logs , We need to make ...

  6. jquery cleditor The cursor often doesn't go in. The solution to the problem bootstrap Rich text box Control

    cleditor The cursor doesn't go in , The reason is embedded html Code segment body No default height assigned . resolvent 1. assignment options.bodyStyle   Set up min-height value . shortcoming : Cannot follow the device to update the minimum height ...

  7. Rich text ,NSAttributedString, When the content that needs to be changed has the same solution

    In the process of development, you may encounter rich text presentation , for example : A line of text , The front is the question and the back is the answer , Questions and answers are written in different colors , But the content of the answer is always in the question , At this time, the usual way will show the error , Because the content of the question has been changed, but the actual answer has not been changed ...

  8. vue Use v-html Command rendering of rich text can not modify the style of the solution

    Current vue Problems encountered in the project :v-html Rendered rich text , Cannot modify style in style sheet resolvent : Put the styles that need to be added or reset separately in one style In the label , Defined as a global style , The code is as follows : <style> ...

  9. selenium Automated testing of ways to enter information in rich text

    For the first time to use selenium+python Writing automatic test scripts , Because rich text editing is inserted into the page , I couldn't enter it at first , Du Niang's many methods are ineffective , Sharing the experience of stepping on a pit is to record one's own growth , The second is to explore for the same purpose seleni ...

Random recommendation

  1. follow 9 Zhang mind map learning Javascript

    The road of learning is to constantly sum up , Better a good memory than a bad pen ,so, Next po This is my collection of 9 Zhang javascript Related mind maps ( Not the original ). Mind mapping is small tips: Mind map is also called mind map , It's the expression of the emission thinking ...

  2. webkit webApp Summary of key points of development technology

    If you're a front end er, I want to develop my own applications on mobile devices , Then how to achieve ? fortunately ,webkit The browser in the kernel can help us do all this . Contact webkit webApp It's been a while since the development of , Now let's share some tips with you ...

  3. C#,PHP Corresponding encryption function

    require_once "JunDes.php"; $jDes=new JunDes(); echo $jDes->encode('98765'); //echo $jDe ...

  4. php Ban eval( ) function

    php Of eval Functions are not system component functions , So we have php.ini Use in disable_functions There's no way to ban it . however eval() about php It's very lethal in terms of safety , Therefore, in general, in order to prevent ...

  5. C Language second blog assignment —— Branching structure

    One .PTA Experiment assignment subject 1: Calculating piecewise functions 1. Experimental code #include<stdio.h> #include<math.h> int main(void) { double x ...

  6. SUSE11sp3 perf Tool installation process

    The working environment is suse11sp3 System ( Kernel version 3.0.101-0.47.90-default), Need to pass through perf Check system performance , But the default is no perf The tool . I searched the Internet for , need linux-tool ...

  7. Hibernate Study ( 8、 ... and )———— Hibernate Search strategy ( Class level , Association level , Batch Search ) Detailed explanation

    preface A lot of things that seem difficult are not difficult , The key is to see if you spend time and energy looking at , If you can understand something , alike , Others can understand it , It doesn't show the gap with others , So when you feel like you've read a lot or learned a lot , Do you want to ...

  8. excel Import 、 export

    http://blog.csdn.net/cjh200102/article/details/12557599 NPOI working copy HSSFWorkbook Construction method , Nonparametric means to create a new workbook , You can receive ...

  9. Effective Java The third edition —— 86. Achieve... With great care SERIALIZABLE Interface

    Tips The source code address in the book :https://github.com/jbloch/effective-java-3e-source-code Be careful , Some of the code in the book is based on Java 9 API Medium , the ...

  10. Wechat applet FAQ

    1. Pay attention to the case of the picture name . Otherwise, the local preview can be seen . After uploading, you can't see it with your mobile phone . 2. bindtap And so on wxml <view id="tapTest" data-hi= ...