Wednesday 8 May 2013

iOS: how to set the height of row dynamically according to text?





+ (CGFloat)heightForCellWithPost:(NSString *)post {
    CGSize sizeToFit = [post sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:CGSizeMake(220.0f, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap];
    
    return fmaxf(70.0f, sizeToFit.height + 45.0f);
}

For fmaxf(float x,float y) :Description
These functions return the larger value of x and y.

Return Value

These functions return the maximum of x and y.
If one argument is a NaN, the other argument is returned.
If both arguments are NaN, a NaN is returned.

Errors

No errors occur.