2014-05-05 70 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

相關問題