IOS Uilabel Text line spacing

Source: Internet
Author: User

A reference to the line spacing of the Uilabel is usually solved by the following method.

UILabel*label = [[UILabelAlloc]initWithFrame: Labelframe];
[LabelSetBackgroundColor:[UicolorClearcolor]];
[LabelSetTextColor: TextColor];
[LabelSetnumberoflines:0];
Label.Font=textfont;
NSString*labeltext=@ "I am content, I am content, I am content, I am content, I am content.";

Nsmutableattributedstring*attributedstring= [[NsmutableattributedstringAlloc]Initwithstring: LabelText];
Nsmutableparagraphstyle*paragraphstyle= [[NsmutableparagraphstyleAlloc]Init];

[ParagraphstyleSetlinespacing:10];//Adjust line spacing

[AttributedstringAddAttribute:Nsparagraphstyleattributename value :p Aragraphstyle :nsmakerange 0,[labeltext length])];
       label. attributedtext = attributedString;
       [contentview addsubview:label";
[Label SizeToFit];
This approach can be achieved if the content you want to show is fully visible in a region. But if you only show a specific two lines, or a few lines, which means you don't need to display all the contents of the label, the above method cannot be reached. Fortunately, someone wrote a ready-made label control for us to use. Tttattributedlabel: Https://github.com/mattt/TTTAttributedLabel

IOS Uilabel Text line spacing

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.