Heres a quick tip to size and textfield to fit the amount of characters in the string with in a tableview cell
Code:
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
float constraintSizeWidth = 262.2
//First get the text you want to display into a string
NSString *cellText = [NSString stringWithFormat:@"%@, myString]];
//set the font to the font style and size you want to display
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];
//create a CGSize variable that holds the bounds of the textfield that you want the string to be restricted too
CGSize constraintSize = CGSizeMake(constraintSizeWidth, MAXFLOAT);
//create the size for the label
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
//return the labelSize + padding
return labelSize.height+20;
}
and then you place these 3 lines of code in your cellForRowAtIndexPath function
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
cell = self.mySelectedCell;
self.mySelectedCell = nil;
}
UILabel *label = (UILabel*)[cell.contentView viewWithTag:1];
[label setFrame:have to set size of frame here];
[label setText:[NSString stringWithFormat:@"%@,myString]];
//This sets the label to word wrap in the cell
[label setLineBreakMode:UILineBreakModeWordWrap];
[label setNumberOfLines:0];
[label sizeToFit];
return cell;
}