Wednesday, October 29, 2014

Adjust cell height dynamically in UITableView

#define GET_BOLD_FONT_WITH_SIZE(__SIZE) ([UIFont fontWithName:FONT_BOLD size:__SIZE])

//Method declaration
-(CGSize)calculateCellHeight:(NSString*)text;

//Usage
cellHeight=[self calculateCellHeight:info.textValue];

///////////////////////////////////////////////////
// Method : calculateCellHeight
// Params : text
// Description : To adjust cell height dynamicaly
//////////////////////////////////////////////////

-(CGSize)calculateCellHeight:(NSString*)text{
    
    CGSize height;
    height = [text sizeWithFont:GET_BOLD_FONT_WITH_SIZE(14)
              constrainedToSize:CGSizeMake(300.0, 1000.0)
                  lineBreakMode:UILineBreakModeWordWrap];

    return height;

}

No comments:

Post a Comment