2014-05-05 74 views
3

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

Desired enumeration style

粉红色的线是不是所期望的效果的一部分,但要强调的普查员应当如何对齐(即它们必须是右对齐,但。左边的文字仍然应该左对齐)。

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

有关我如何根据需要调整统计员的任何想法?

回答

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}]]; 
+1

如果你能提供一个更完整的例子,我将不胜感激。 – hfossli

相关问题