:
Code:
- (void) viewdidload{[Super Viewdidload]; //Do any additional setup after loading the view. //automatically adjusts height based on contentNSString *str =@"In the 3000 BC, the number of inhabitants of the Indus Valley has been widely used, and residents have adopted the decimal system method of calculation. "; Uifont*font = [Uifont systemfontofsize: -]; Cgsize size= Cgsizemake ( $, -); CGRect Labelrect= [str boundingrectwithsize:size options: (nsstringdrawinguseslinefragmentorigin|nsstringdrawingusesfontleading) attributes:[nsdictionary Dictionarywithobject:font forKey:NSFontAttributeName ] Context:nil]; //UILabelUILabel *label = [[UILabel alloc]initwithframe:cgrectmake ( -, -, LabelRect.size.width, LabelRect.size.height)]; Label.text=str; Label.backgroundcolor=[Uicolor Redcolor]; Label.font= [Uifont systemfontofsize: -]; Label.numberoflines=0; [Self.view Addsubview:label];}
Uilabel automatically adjusts height based on content