Eya*_*yal 9 iphone objective-c uilabel core-text ios
这个问题是关于在iOS中实现文本缩进("将文本放在更远的位置以将其与周围文本分开").
以下面的文字为例:
请注意,第2部分中的第二行从右侧开始,在上方的线下方.
我的代码包含一个数组NSString,每个应该显示为带有上面数字项目符号的部分.例如:
NSArray *array = [NSArray arrayWithObjects:@"1. This is the first section.", @"2. This is the second one, with two lines.", @"3. This is the third.", nil];
Run Code Online (Sandbox Code Playgroud)
我用来UILable在屏幕上显示文字.
要将文本从数组设置为标签,并将我使用的新行中的每个字符串分开
myLabel.text = [array componentsJoinedByString:@"\n"];
Run Code Online (Sandbox Code Playgroud)
任何想法如何获得这种效果?
Bri*_*kel 25
这在iOS6中可以在某种程度上实现- [UILabel setAttributedText:].
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.headIndent = 29;
myLabel.attributedText = [[NSAttributedString alloc] initWithString:
@"1.\tShort line.\n2.\tLong line with content that triggers wrapping.\n3.\tShort line."
attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];
Run Code Online (Sandbox Code Playgroud)

这会为后续行添加缩进.看起来iOS不像OSX那样支持制表位,所以我没有看到调整数字和文本之间差距的方法.这在CoreText中可能是可能的.
当然,您也可以使用a替换标签,UIWebView并以性能为代价对所有iOS版本进行完全格式化控制.
好吧,我决定自己实现它,而不使用 Core Text,我只是创建了一个视图结构,使所有缩进自行工作,并让您根据需要自定义它。
对于所有对实现感兴趣的人,您可以在此处查看源代码和示例项目:
ECListView Project
| 归档时间: |
|
| 查看次数: |
6407 次 |
| 最近记录: |