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