2014-09-19 22 views
0

高度I與的UIAlertViewStylePlainTextInputalertViewStyle一個UIAlertView。我試圖找到一種方法來使UIAlertViewUITextField調整其高度,並根據用戶輸入的內容來包裝其文本。iOS的目標C渦卷文本並動態地調整基於內容

說實話,我沒有絲毫的線索如何做到這一點。

下面是我的一些代碼:

-(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]; 
} 
+0

它不可能爲UITextField,因爲文本字段只需要1行文本。所以你必須用UITextView創建自定義警報 – 2014-09-19 20:10:37

回答

0

它是不可能有多個線條和動感高度UITextField

要實現此目的,請創建自定義提醒並添加UITextView,因爲UITextView可以有多行。覆蓋textViewDidChange:並使用 sizeWithFont:constrainedToSize:lineBreakMode:計算文本視圖中文本的大小。它會根據高度調整UITextView的高度和警報返回CGSize

謝謝