Nic Hubbard
Nic Hubbard

Reputation: 42139

UITextField Autoresize in UITableViewCell

I have a UITextField inside of a UITableView cell. When I rotate the device, the textfield is still the same width it was for Portrait mode. I know that I need to use autoresizing to make the field fill the cell when I am in landscape, but I am not sure how to do this, as I have tried and failed.

How would I do this?

cell.textLabel.text = @"Email";
UITextField *field2 = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, width, 30)];
field2.adjustsFontSizeToFitWidth = YES;
field2.textColor = [UIColor blackColor];
field2.keyboardType = UIKeyboardTypeEmailAddress;
field2.returnKeyType = UIReturnKeyNext;
field2.placeholder = @"Required";
field2.tag = 3;
field2.delegate = self;
field2.autoresizingMask =  UIViewAutoresizingFlexibleWidth;
field2.backgroundColor = [UIColor blueColor];
// Finish building cell
field2.autocorrectionType = UITextAutocorrectionTypeNo;
field2.autocapitalizationType = UITextAutocapitalizationTypeNone;
field2.textAlignment = UITextAlignmentLeft;
[field2 addTarget:self action:@selector(updateFields:) forControlEvents:UIControlEventEditingChanged];
field2.text = email;
self.emailField = field2;
[cell addSubview:field2];
[field2 release];

Upvotes: 0

Views: 2141

Answers (1)

k-thorat
k-thorat

Reputation: 5123

  1. Check if you tableView has Auto Resize subivew is set to YES.
  2. Check you are returning YES for all the supported rotations.
    • (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration: (NSTimeInterval)duration{ }

Upvotes: 2

Related Questions