http://ios-iphone.diandian.com/post/2012-03-29/18389515
-(int) getattributedstringheightwithstring: (nsattributedstring *) string widthvalue: (int) width
{
int total_height = 0;
Ctframesetterref Framesetter = ctframesettercreatewithattributedstring ((cfattributedstringref) string); String is the nsattributedstring to calculate the height
CGRect drawingrect = CGRectMake (0, 0, width, 1000); The Gaoyao setting here is large enough
Cgmutablepathref path = cgpathcreatemutable ();
Cgpathaddrect (Path, NULL, Drawingrect);
Ctframeref textFrame = Ctframesettercreateframe (Framesetter,cfrangemake (0,0), path, NULL);
Cgpathrelease (path);
Cfrelease (Framesetter);
Nsarray *linesarray = (Nsarray *) ctframegetlines (textFrame);
Cgpoint Origins[[linesarray Count]];
Ctframegetlineorigins (TextFrame, cfrangemake (0, 0), Origins);
int line_y = (int) origins[[linesarray count] -1].y; The y-coordinate of the last line's origin.
CGFloat ascent;
CGFloat descent;
CGFloat leading;
Ctlineref line = (ctlineref) [Linesarray Objectatindex:[linesarray count]-1];
Ctlinegettypographicbounds (line, &ascent, &descent, &leading);
Total_height = 1000-line_y + (int) descent +1; +1 to correct the value of descent converted to int after decimal point
Cfrelease (TextFrame);
return total_height;
}
about line coordinate position y for the black line position descent is the height of the lower part of the black line
About Font Sections Height description http://ios-iphone.diandian.com/post/2012-03-29/18055023
30, accurate calculation of coretext height method