#pragma mark-once Get text height
-(Cgsize) Sizewithmaxsize: (cgsize) size antext: (NSString *) anstring
{
nsmutableattributedstring *attributedstring = [[Nsmutableattributedstring alloc] initwithstring:anstring];
Nsmutableparagraphstyle *style = [[Nsmutableparagraphstyle alloc]init];
[Style setlinespacing:6.0f];
[Attributedstring addattribute:nsparagraphstyleattributename Value:style range:nsmakerange (0, [anString length])];
Cgsize realsize = Cgsizezero;
if (System_version_greater_than_or_equal_to (@ "7.0")) {
CGRect textrect = [anstring boundingrectwithsize:size options:nsstringdrawinguseslinefragmentorigin attributes:@{ Nsfontattributename:[uifont Systemfontofsize:myconsuldetailframefontsize],nsparagraphstyleattributename:style} Context:nil];
Realsize = textrect.size;
} else {
Realsize = [anstring sizewithfont:[uifont systemfontofsize:myconsuldetailframefontsize] maxSize:size lineBreakMode: Nslinebreakbycharwrapping];
}
Realsize.width = Ceilf (realsize.width);
Realsize.height = Ceilf (realsize.height);
return realsize;
}
This article is from the "11204872" blog, please be sure to keep this source http://11214872.blog.51cto.com/11204872/1770197
IOS Compute Text Height