IOS: Setting Uilabel Leading instances

Source: Internet
Author: User

Tag:ios   uilabel    instance     layout    

    Create UILabel UILabel *label = [[UILabel alloc]initwithframe:cgrectmake (7, 5, Tableview_width-headimgview_height-    20-24-20, 0)];    Line wrap label.numberoflines = 0;    Set the label content width cgfloat textWidth = 414;    Get data NSString *text = model.content; Create a nsmutableattributedstring instance and pass text to nsmutableattributedstring *attstr = [[Nsmutableattributedstring alloc]    Initwithstring:text];    Create Nsmutableparagraphstyle instance Nsmutableparagraphstyle *style = [[Nsmutableparagraphstyle alloc]init];    Set line spacing [style setlinespacing:10.0f];    Determines whether the content length is greater than the label content width, if not greater than, sets the content width to line width (content if small exist, label length is too short, if the label has a background color, will affect the layout effect) Nsinteger leng = textWidth;    if (Attstr.length < textWidth) {leng = Attstr.length; }//Set ATTSTR style according to the given length and style [Attstr addattribute:nsparagraphstyleattributename Value:style range:nsmakerange (0, Leng)    ];    Label gets ATTSTR model Label.attributedtext = ATTSTR;    Label adaptive size [Label SizeToFit]; Set Label Height label.height = label. frame.size.height; 
This method can not only set the label line spacing, but also can set the adaptive height

IOS: Setting Uilabel Leading instances

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.