如何在UILabel.text中添加制表符空间 [英] how to add tab space into UILabel.text

查看:135
本文介绍了如何在UILabel.text中添加制表符空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UILabel实例,比如mylabel。

I have a UILabel instance, say mylabel.

我想做的是这样的:

mylabel.text = @"Age\tLimit\tYear"; 

instead of  

mylabel.text = @"Age           Limit       Year";

但是当我尝试时,\t无法识别。如何实现呢?

But when i tried, \t is not recognized. How to achieve it?

推荐答案

您还可以先格式化字符串

You can also format string first

NSString *formattedString = [NSString stringWithFormat:@"Age%8s%8s",[@"Limit" UTF8String], [@"Year" UTF8String]];

mylabel.text = formattedString;

不幸的是,%@ formatter不会添加空格来调整字段宽度。
所以我使用带有%s说明符的UTF8String来调整宽度。

Unfortunately, %@ formatter doesn't add spaces to adjust field width. So I use UTF8String with %s specifier to adjust width.

注意:
Width指定要输出的最小字符数,通常是用于填充表格输出中的固定宽度字段,否则字段会更小,但不会导致超大字段的截断。

Note: Width specifies a minimum number of characters to output, and is typically used to pad fixed-width fields in tabulated output, where the fields would otherwise be smaller, although it does not cause truncation of oversized fields.

这篇关于如何在UILabel.text中添加制表符空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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