3

Text Kit を使用して、自分のアプリでカスタム テキストをレイアウトしています。適切に配置された列挙子を使用して、見栄えの良いリストを作成したいと考えています。テキストを次のようにする必要があります。

望ましい列挙スタイル

ピンクの線は目的の効果の一部ではありませんが、列挙子の配置方法を強調するためのものです (つまり、列挙子を右揃えにする必要がありますが、左側のテキストは左揃えにする必要があります)。

私はリスト スタイルを実装してこの要件を満たしています (現在、列挙子は左揃えになっています)。これを行うには、列挙子を文字列として追加し、その後にタブ文字 ( \t) を追加し、カスタム タブ ストップ ( NSTextTab) を目的の位置に追加しますNSParagraphStyle。以降の行は、headIndentを と同等の位置に設定することによってインデントされますNSTextTab

必要に応じて列挙子を整列させる方法について何か考えはありますか?

4

1 に答える 1

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}]];
于 2014-05-05T20:53:18.163 に答える