0

I have a UITableViewCell that has a textLabel and a UITextField attached as a subview like this:

cell = [tableView dequeueReusableCellWithIdentifier:Value1CellIdentifier];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:Value1CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = @"Name";
UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
playerTextField.adjustsFontSizeToFitWidth = YES;
playerTextField.textColor = [UIColor blackColor];
playerTextField.placeholder = @"John Doe";
playerTextField.textAlignment = UITextAlignmentLeft;
[playerTextField setEnabled: YES];
[cell addSubview:playerTextField];
[playerTextField release];

The textLabel takes up way to much space. How can I set the width of the textLabel, so that the rest of the UITableViewCell gets the reminding width?

Thank you

Neigaard
  • 3,726
  • 9
  • 49
  • 85

2 Answers2

1

textLabel is read-only. Why not create your own and add that to the cell?

Joseph Tura
  • 6,290
  • 8
  • 47
  • 73
  • Well actually i can just set the position of my added subview to a more "left" one, and it works :) – Neigaard Nov 01 '10 at 19:07
1

In short, you could set the width of the UITextLabel inside a UITableViewCell using the layoutSubviews method, which is executed in the UITableViewCell class. Using it would require you to most likely create your own custom UITableViewCell class like Joseph Tura mentioned.

A posted answer in the following link has a great example on how to use layoutSubviews: Having a UITextField in a UITableViewCell

This solution outlines an alternate approach as well: How to put a UITextField inside of a UITableViewCell (grouped)?

Community
  • 1
  • 1
avelis
  • 1,143
  • 1
  • 9
  • 18