IOS set Uilabel line spacing and self-adapting height

Source: Internet
Author: User

NSString *contentstr = @ "always thought, in the original place, there is a most original me, will also have a most original you";    UILabel *templabel = [[UILabel alloc] init];    Set background Color Templabel.backgroundcolor = [Uicolor Redcolor];    Set content Templabel.text = Contentstr;    Set Font Color Templabel.textcolor = [Uicolor Whitecolor];    Set Font Size Templabel.font = [Uifont systemfontofsize:15.0];    Sets whether the text is multiple lines templabel.numberoflines = 0;    Templabel.linebreakmode = nslinebreakbywordwrapping;    Set Uilabel according to the text adaptive height cgsize size = [Templabel sizethatfits:cgsizemake (maxfloat)];    Set Frame Templabel.frame = CGRectMake (+, +, size.height);    [Self.view Addsubview:templabel]; Set the line spacing of the label nsmutableattributedstring *attributedstring = [[Nsmutableattributedstring alloc] initwithstring:    CONTENTSTR];    Nsmutableparagraphstyle *paragraphstyle = [[Nsmutableparagraphstyle alloc] init];    [Paragraphstyle Setlinespacing:8]; [Attributedstring addattribute:nsparagraphstyleattributename Value:paragraphstyle Range:NSMakeRange(0, [contentstr length])];    [Templabel setattributedtext:attributedstring]; [Templabel SizeToFit];

IOS set Uilabel line spacing and self-adapting height

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.