ios - iOS7中如何根据内容调整UITextField的大小?

标签 ios uitextfield xcode5.1

虽然我有很多关于如何根据其中添加的内容调整 UITextField 大小的链接,但我的 TextField 没有随文本一起增长。可能是我遗漏了什么。 我也尝试过我在搜索这个问题时得到的这个方法,但它仍然没有用。我知道我错过了一些东西。但没有得到确切的东西。

- (IBAction) textFieldDidChange: (UITextField*) textField
{
    [UIView animateWithDuration:0.1 animations:^{
        [textField invalidateIntrinsicContentSize];
    }];
}

我正在使用 Xcode 5.1.1 来兼容 iOS7。 谁能帮助我错过了什么? 提前致谢

最佳答案

您可以更改文本字段的高度,但您不能在文本字段中使用多行数据,而是可以使用如下所示的 textview:

UITextView *textView=[UITextView alloc]init];
textView.frame= CGRectMake(20,20, 455, 80);
textView.layer.cornerRadius=6;
textView.font = [UIFont systemFontOfSize:15.0];
textView.layer.borderWidth=1;
textView.layer.borderColor=[[UIColor grayColor] CGColor];
textView.textColor=[UIColor blackColor];
textView.editable=YES;
[self.view addSubView:textView];

关于ios - iOS7中如何根据内容调整UITextField的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25284213/

相关文章:

ios - 如何限制 UITextView iOS 中的字符

ios - Swift 将数组作为参数传递错误

iOS( swift ): UITextField is **not** first responder after becomeFirstResponder method is called?

ios - 由于未捕获的异常而终止应用程序。 "nil string parameter"

IOS Xcode 5.1 在单独的行中搜索路径

ios - 如何获得自 iOS 设备启动以来的准确时间?

objective-c - 如何访问 viewController 中的方法

ios - 如何在编辑时更改 uitextfield leftView image tintColor

iphone - 如何选择 UITextField?

ios - 如何在 Xcode 5.1 中使用图标