Copy Code code as follows:
Txtlbl.font = [Uifont boldsystemfontofsize:14.0f];
Txtlbl.numberoflines = 0;
NSString *str = @ "Albania decided to set up a network of science and technology to leave the TV show cent W amount of two mainland high technology got lost day I countdown left I said teacher KFC Franksa Jiangdong Elders will Roger Federer said Albania decided to set up a network of science and technology to leave the TV show two of the mainland High-tech got lost day I countdown away Open My branch said the teacher Kentucky Franksa Jiangdong Elders will Federer said ";
Cgsize size = [str sizeWithFont:txtlbl.font constrainedtosize:cgsizemake (txtlbl.frame.size.width, Maxfloat) Linebreakmode:nslinebreakbywordwrapping];
Reset the size of the TXTLBL based on the results
[Txtlbl Setframe:cgrectmake (7, 0, 310, size.height)];
Txtlbl.text = str;
Method Two:
Copy Code code as follows:
Ios7_api_ determines the label width according to the word Word character dynamic
Sets the font for the label Helveticaneue Courier
Uifont *fnt = [Uifont fontwithname:@ "Helveticaneue" size:24.0f];
_namelabel.font = FNT;
According to the font to get nsstring size
Cgsize size = [_namelabel.text sizewithattributes:[nsdictionary dictionarywithobjectsandkeys:fnt, Nsfontattributename, Nil]];
The h of the name
CGFloat Nameh = size.height;
Name of the W
CGFloat Namew = size.width;
_namelabel.frame = CGRectMake (0, 0, Namew,nameh);
Method Three:
Copy Code code as follows:
Width W
CGFloat contentw = self.bounds.size.width-_content.frame.origin.x-kmargin;
Label's font helveticaneue Courier
Uifont *fnt = [Uifont fontwithname:@ "Helveticaneue" size:18.0f];
_content.font = FNT;
_content.numberoflines = 0;
_content.linebreakmode = nslinebreakbywordwrapping;
IOS7 replaces the SizeWithFont:constrainedToSize:lineBreakMode in obsolete iOS6 with the following methods: Method
CGRect tmprect = [_content.text boundingrectwithsize:cgsizemake (CONTENTW, 1000) options: Nsstringdrawinguseslinefragmentorigin Attributes:[nsdictionary Dictionarywithobjectsandkeys:fnt, Nsfontattributename, nil] context:nil];
Height h
CGFloat contenth = tmpRect.size.height;
NSLog (@ "Adjusted display width:%f, display height:%f" contentw,contenth);
_content.frame = CGRectMake (0, 0, contentw,contenth);