让UILabel生成省略号而不是缩小字体 [英] Getting UILabel to produce an ellipsis rather than shrinking the font

查看:290
本文介绍了让UILabel生成省略号而不是缩小字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我动态更改UILabel的文本时,我宁愿得到省略号(点,点,点),而不是自动调整文本大小。如何做到这一点?

When I dynamically change the text of a UILabel I would prefer to get an ellipsis (dot, dot, dot) rather then have the text be automatically resized. How does one do this?

换句话说,如果我有UILabel,单词 Cat ,大小为14然后我将单词更改为 Hippopotamus 字体缩小以适合所有单词。我希望自动截断单词后跟省略号。

In other words, if I have UILabel with the word Cat with size font 14 and then I change the word to Hippopotamus the font shrinks to fit all the word. I would rather the word be automatically truncated followed by an ellipsis.

我假设有一个参数可以在我的UILabel对象中更改。我宁愿不以编程方式执行此操作。

I assume there is a parameter that can be changed within my UILabel object. I'd rather not do this programmatically.

推荐答案

设置以下属性:

label.adjustsFontSizeToFitWidth = NO;
label.lineBreakMode = NSLineBreakByTruncatingTail;

您还可以在界面构建器中设置这些属性。

You can also set these properties in interface builder.

这篇关于让UILabel生成省略号而不是缩小字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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