如何根据iOS7的内容调整UITextField的大小



虽然我有很多关于如何根据里面添加的内容调整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];

最新更新