UILabel *filenamelabel = [[UILabelalloc]init ];
[Filenamelabel setbackgroundcolor: [uicolorclearcolor< /c14>]];
[Filenamelabel setFont: [uifontsystemfontofsize: C7>14]];
[Filenamelabel setnumberoflines:0];
[Filenamelabel setlinebreakmode:nslinebreakbytruncatingmiddle] When text exceeds a certain size, the middle padding ellipsis
// calculates the actual frame size and turns the label frame to the actual size
cgsizelabelsize = [Text boundingrectwithsize:Cgsizemake(Width,Height) Options:Nsstringdrawinguseslinefragmentoriginattributes:@{Nsfontattributename: Filenamelabel.Font}Context:Nil].size//text for the string to be displayed, width is set to the text widths that need to be displayed, and height is the maximum text height. This method is only available for ios7.0 and above versions .
[Filenamelabel setframe:cgrectmake(x, y, labelsize. width , Labelsize. Height ];//x is the horizontal coordinate of the label, and Y is the label's vertical coordinate.
[Filenamelabel setText: Text];
[view addsubview: Filenamelabel];
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UILabel multi-line text and dynamically calculate its height