Thursday, 13 February 2014

UITableViewCell with dynamic height

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

        //This code for Tableview with basic type Cell
        CGFloat defaultRowHeight=44;
        NSString *cellText; //Give cell text here from the data source Array of TableView
        UIFont *cellFont ;  //Give cell font here 
        CGSize constraintSize = CGSizeMake(220, MAXFLOAT);
        CGSize labelSize = [cellText boundingRectWithSize:constraintSize
                                                  options:NSStringDrawingUsesLineFragmentOrigin
                                               attributes:@{NSFontAttributeName:cellFont}context:nil].size;
        CGFloat rowHeight =  labelSize.height;
        return   MAX(rowHeight, defaultRowHeight);
    }

No comments:

Post a Comment