iOS UITextField自动调整大小符合内容 [英] iOS UITextField Auto Resize conform to the content

查看:932
本文介绍了iOS UITextField自动调整大小符合内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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,文本必须适合一行,



您有两个选项:


  1. 收缩该字体适合一行:



    self.TextFieldExample.adjustsFontSizeToFitWidth = YES;
    self.TextFieldExample.minimumFontSize = 10.0; //可选指定最小尺寸 c>


  2. 使用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:

  1. Shrink the font to fit on one line:

    self.TextFieldExample.adjustsFontSizeToFitWidth = YES; self.TextFieldExample.minimumFontSize = 10.0; //Optionally specify min size

  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆