iOS Objective-C在UIAlertView中包装UITextField的文本,并根据内容动态调整高度

iOS Objective-C在UIAlertView中包装UITextField的文本,并根据内容动态调整高度,ios,objective-c,uialertview,Ios,Objective C,Uialertview,我有一个UIAlertView,其alertViewStyle为UIAlertViewStylePlainTextInput。我试图找到一种方法,使UIAlertView的UITextField在用户键入时根据其内容调整其高度并包装其文本 老实说,我一点儿也不知道该怎么做 以下是我的一些代码: -(void)updateTicket:(id)sender { UIButton *sndr = (UIButton*)sender; int index = sndr.tag;

我有一个UIAlertView,其alertViewStyle为UIAlertViewStylePlainTextInput。我试图找到一种方法,使UIAlertView的UITextField在用户键入时根据其内容调整其高度并包装其文本

老实说,我一点儿也不知道该怎么做

以下是我的一些代码:

-(void)updateTicket:(id)sender
{
    UIButton *sndr = (UIButton*)sender;
    int index = sndr.tag;

    UIAlertView *alert = [[UIAlertView alloc] init];
    [alert setTag:-7];
    [alert setDelegate:self];
    [alert setTitle:[NSString stringWithFormat:@"Update Ticket #%i", [ticketIDs[index] intValue]]];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    [alert textFieldAtIndex:0].placeholder = @"Note";
    [alert textFieldAtIndex:0].tag = index;
    [alert textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeSentences;
    [alert textFieldAtIndex:0].autocorrectionType = UITextAutocorrectionTypeYes;
    [alert textFieldAtIndex:0].autoresizingMask = UIViewAutoresizingFlexibleHeight;
    [alert addButtonWithTitle:@"Cancel"];
    [alert addButtonWithTitle:@"OK"];
    [alert setCancelButtonIndex:0];
    [alert show];
}

不可能有一个具有多行和动态高度的UITextField

要实现此目的,请创建自定义警报并添加UITextView,因为UITextView可以有多行。覆盖textViewDidChange:并使用 sizeWithFont:constrainedToSize:lineBreakMode:。它将根据高度返回CGSize,并调整UITextView和警报的高度


谢谢

UITextField不可能,因为textfield只接受一行文本。因此,您必须使用UITextView创建自定义警报