iOS UITextField自动调整大小符合内容 [英] iOS UITextField Auto Resize conform to the content
问题描述
如何在iOS中在文本字段中设置自动调整大小?
helloWorld.m
code> self.TextFieldExample.text = @HELLO WORLD HELLLO WORLD HELLO WORLD HELLO WORLD;
现在:
HELLO WORLD HELLO ...
正确:
HELLO WORLD HELLO WORLD HELLLO WORLD HELLO WORLD
这种情况下最好的做法是什么?
使用UITextField,文本必须适合一行,
您有两个选项:
-
收缩该字体适合一行:
self.TextFieldExample.adjustsFontSizeToFitWidth = YES;
self.TextFieldExample.minimumFontSize = 10.0; //可选指定最小尺寸 c>
-
使用UITextView启用文字换行: b
$ b查看此答案:如何创建多行UITextfield ?
ps 根据样式指南,属性应为骆驼案例与 。因此,您应该将var重命名为 self.textFieldExample
How I can set the Auto resize in Text Field in iOS ?
helloWorld.m
self.TextFieldExample.text = @"HELLO WORLD HELLO WORLD HELLO WORLD HELLO WORLD";
Now:
HELLO WORLD HELLO ...
Correct:
HELLO WORLD HELLO WORLD HELLO WORLD HELLO WORLD
What is the best practice in this case?
With a UITextField, text must fit on one line and cannot wrap.
You have two options:
Shrink the font to fit on one line:
self.TextFieldExample.adjustsFontSizeToFitWidth = YES;
self.TextFieldExample.minimumFontSize = 10.0; //Optionally specify min size
Use UITextView to enable text wrapping:
See this answer: How to create a multiline UITextfield?
p.s. Per the style guide, "Properties should be camel-case with the leading word being lowercase." so you should rename your var to self.textFieldExample
这篇关于iOS UITextField自动调整大小符合内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!