虽然我有很多关于如何根据其中添加的内容调整 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/