【问题标题】:How To Resize UITextField According to the Content in iOS7?如何根据 iOS7 中的内容调整 UITextField 的大小?
【发布时间】:2014-08-13 10:50:56
【问题描述】:

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

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

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

【问题讨论】:

  • 使用 Textview 代替 textfield。

标签: ios uitextfield xcode5.1


【解决方案1】:

您可以更改文本字段的高度,但不能在文本字段中使用多于一行的数据,而是可以使用如下所示的 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];

【讨论】:

    猜你喜欢
    • 2013-11-19
    • 2021-05-16
    • 1970-01-01
    • 2011-01-28
    • 2016-08-04
    • 2010-09-08
    • 1970-01-01
    • 2012-02-09
    相关资源
    最近更新 更多