将制表符向右对齐,然后向左对齐

时间:2014-05-05 18:15:10

标签: ios uitextview textkit

我正在使用Text Kit在我的应用程序中布局一些自定义文本,我想创建漂亮的列表,并使用正确对齐的枚举器。我需要文字看起来像这样:

Desired enumeration style

粉色线不是所需效果的一部分,而是强调枚举器应如何对齐(即,它们需要右对齐,但左侧的文本仍应左对齐)。

我有列表样式实现吧这个要求(枚举器目前是左对齐的)。我这样做是通过将枚举数添加为字符串,在其后面添加制表符(\t),并在所需位置添加自定义制表位(NSTextTab)到{{1} }。通过将NSParagraphStyle设置为与headIndent等效的位置来缩进后续行。

有关如何根据需要调整枚举数的想法吗?

1 个答案:

答案 0 :(得分:4)

想出来。事实证明,我可以使用NSTextTab s执行此操作,如下所示:

NSString *enumerator = @"\t\u2022\t"; // Bullet symbol

NSMutableParagraphStyle *enumeratorParagraphStyle = [paragraphStyle mutableCopy];
NSTextTab *enumeratorTabStop = [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentRight
                                                               location:eMarkdownRendererIndentationPoints
                                                                options:nil];
NSTextTab *contentTabStop = [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentLeft
                                                            location:contentLocation
                                                             options:nil];

enumeratorParagraphStyle.tabStops = @[enumeratorTabStop, contentTabStop];
[textStorage appendAttributedString:[[NSAttributedString alloc] initWithString:enumerator
                                                                    attributes:@{NSParagraphStyleAttributeName: enumeratorParagraphStyle}]];
相关问题