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