iphone - UITableViewCell 中的 UITextField 自动调整大小

标签 iphone objective-c ios uitextfield

我在 UITableView 单元格中有一个 UITextField。当我旋转设备时,文本字段的宽度仍然与纵向模式下的宽度相同。我知道当我处于横向时,我需要使用自动调整大小来使字段填充单元格,但我不确定如何执行此操作,因为我已经尝试过但失败了。

我该怎么做?

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];

最佳答案

  1. 检查您的 tableView 是否将 Auto Resize subivew 设置为 YES。
  2. 检查您是否为所有支持的旋转返回 YES。
    • (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 持续时间: (NSTimeInterval)持续时间{

关于iphone - UITableViewCell 中的 UITextField 自动调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6794637/

相关文章:

UINavigationBar 中的 iOS 11 UISearchBar

ios - WKWebView中如何实现 "Are you sure you want to submit the form again"

iphone - 如何检测TCP连接丢失?

objective-c - 如何在两个字符串中查找公共(public)子字符串

iphone - 如何显示 Game Center 成就通知

objective-c - 将 nil 添加为 subview 是个坏主意吗?

objective-c - 频繁(5Hz)核心数据保存的性能开销

iphone - 通过 USB 从 Linux 控制 iDevice

iphone - iPhone游戏咖啡馆音效

iphone - 如何在终端中显示 Xcode 错误消息和输出?