objective-c 在 UITextField 中包装文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2068115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wrap Text in UITextField?
提问by lab12
Does anyone know how to wrap text in a UITextField? I am using Cocoa/Objective-C in Xcode for my iPhone project, and I can not seem to find a way to do this...
有谁知道如何将文本包装在 a 中UITextField?我在 Xcode 中为我的 iPhone 项目使用 Cocoa/Objective-C,但我似乎找不到办法做到这一点......
回答by Steve Harrison
UITextFieldis meant for single-line text only. If you want multiple lines of text, then you'll have to use the UITextViewclass instead.
UITextField仅适用于单行文本。如果您想要多行文本,则必须改用UITextView该类。
It's worth noting that UITextViewinherits from UIScrollView, so if you don't want scrolling, you may want to stick with the UITextFieldand put up with the text being on one line... I once tried to subclass UITextViewto make it like a multiple-line UITextField, but the UIScrollViewmade the task a nightmare—in the end I just went back to using a simple UITextField.
值得注意的是,UITextView继承自UIScrollView,所以如果你不想滚动,你可能想要坚持UITextField并忍受文本在一行上......我曾经尝试过子类化UITextView以使其像多行一样UITextField,但这UIScrollView使任务成为一场噩梦——最后我又回到使用简单的UITextField.

