截断 UILabel 中的部分文本 [英] Truncate part of text in UILabel

查看:48
本文介绍了截断 UILabel 中的部分文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是我需要以这样一种方式在标签中显示文本,如果文本的长度太大而无法容纳在一行中,我需要在最后截断它,以便只有最后几个字符(通常是 b/w 1-1000 的数字,因此文本长度可能会有所不同.)是可见的,并且在被..."截断之前的文本.

My requirement is that I need to display text in label in such a way that if the length of text is too big to accommodate in one line, i need to truncate it at the end in such a way that only the last few characters(usually a number b/w 1-1000 so text length may vary.) are visible and the text before it is truncated with "...".

所以文本看起来像abcdefgijk...10"

So the text will look something like "abcdefgijk...10"

有什么办法可以做到这一点吗?

Is there any way I can achieve this?

推荐答案

UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(50,100, 150, 30)];
contentLabel.text = @"abcdefghijklmnopqrstuvwxyz10";
contentLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;

将此标签添加到您的显示器.你应该得到这样的输出

Add this label to your display. You should get a output something like this

abcdefghijklmnopq...10

这篇关于截断 UILabel 中的部分文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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