Define Macros:
#define Kfontsize
#define Kphotocell_width
#define Kphotocell_marginbetween 3
#define Kphotocell_titlelabel_height
//method:
+ (cgfloat) Heightforrowwithmodel: (photoinfo *) photoinfo
{
//1. the height of the picture
// let Picture scale scale
//(1) get pictures
UIImage *image = [UIImageimagewithcontentsoffile: [[ NSBundlemainbundle] pathforresource:@ "Tsummer" OfType:@ "PNG"];
//(2) Calculate the height of the picture
cgfloat imageheight = [ self heightforimage: image];
//2. height of text
cgfloat textHeight = [ self heightfortext:p hotoinfo. Introduction];
//3. returns The total height of the cell
return kphotocell_titlelabel_height + imageheight + textHeight +4 * kphotocell_marginbetween;
}
// Calculate the height of the picture separately
+ (cgfloat) heightforimage: (UIImage *) image
{
//(1) get the size of the picture
cgsize size = image. size;
//(2) to find the scaling ratio
cgfloat scale = kphotocell_width /size. width;
cgfloat imageheight = size. height * scale;
return ImageHeight;
}
// Calculate the height of the text separately
+ (cgfloat) Heightfortext: (nsstring *) text
{
// Set the size of the font when calculating text and what criteria to calculate
nsdictionary *attrbute = @{nsfontattributename: [uifont Systemfontofsize:kfontsize]};
return [text boundingrectwithsize:cgsizemake(kphotocell_width ,nsstringdrawingusesfontleading) Options:( | Nsstringdrawinguseslinefragmentorigin) attributes: Attrbutecontext:Nil ]. size . Height ;
}
iOS automatically gets the height of the lable