IOS Label Adaptive Height adaptation iOS7 later versions more
Self.contentlabelview = [[UILabel alloc] init];
Self.contentLabelView.font = Sys_font (15);
Self.contentLabelView.lineBreakMode =nslinebreakbytruncatingtail;
Self.contentLabelView.textColor = [Uicolor colorwithhexstring:@ "#444444"];
Self.contentLabelView.text =[@ "12312312312312321321dddsdadsadasdasdas" stringbyappendingstring:@ "\n\n\n\n\n\n\n" ];
[Self.contentlabelview setnumberoflines:0];
Calculates the height required for a label based on the content
cgsize size = Cgsizemake (kscreenwidth-expectsizes.width-20, maxfloat);
Nsdictionary * Tdic = [Nsdictionary dictionarywithobjectsandkeys:self.contentlabelview.font,nsfontattributename,nil ];
Cgsize actualsize =[self.contentlabelview.text boundingrectwithsize:size options: Nsstringdrawinguseslinefragmentorigin Attributes:tdic context:nil].size;
Self.contentLabelView.frame =cgrectmake (expectsizes.width+20, 254, Actualsize.width, actualsize.height);
The plain code layout may be used, but xib or storyboard are recommended.
IOS UILabel Adaptive height based on content