UITextField - 多行输入

4
我正在尝试在我的UITextField中添加行(我的代码如下),但是当输入者到达文本框的末尾时,它不会跳到下一行,而是一直在同一行上!我该如何让它跳到下一行?谢谢。
fldNotes = [[UITextField alloc] initWithFrame:CGRectMake(labelLeft,controlTop+5,320 - (2 * labelLeft),200)];
fldNotes.text = te.notes;
fldNotes.placeholder = [theApp.adb GetHC:@"NotesName"];
fldNotes.clearButtonMode = UITextFieldViewModeWhileEditing;
fldNotes.tag = 100;
fldNotes.borderStyle = UITextBorderStyleRoundedRect;
[fldNotes setReturnKeyType:UIReturnKeyDone];
[fldNotes setEnablesReturnKeyAutomatically:YES];
fldNotes.delegate = self;

[contentView addSubview:fldNotes];
2个回答

1
您还可以通过使用此功能将自定义的UITextView设置成与UITextField相似的外观。
 myTextView.layer.cornerRadius = 5;
    [myTextView.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
    [myTextView.layer setBorderWidth:2.0];    
    myTextView.clipsToBounds = YES;

不要忘记 import <QuartzCore/QuartzCore.h>,这样你就可以摆脱错误了。
希望这能帮到某个人 :)

1
你试图模仿的风格不会随着IOS版本的变化而改变吗? - Pedro Borges

1

使用UITextView代替。这样可以允许多行文本。


请注意,UITextView 没有 UITextField 的所有功能,如占位符文本,并使用返回键关闭键盘是困难/不良实践。 - HenryRootTwo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接