0

属性付きの文字列を作成し、条件付きで取り消し線を適用しています。コードは次のとおりです。

    NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
    if (needsStrikeThrough) {
        [attributes setValue:[NSNumber numberWithInt:NSUnderlineStyleSingle] forKey:NSStrikethroughStyleAttributeName];
    } else {
        [attributes setValue:[NSNumber numberWithInt:NSUnderlineStyleNone] forKey:NSStrikethroughStyleAttributeName];
    }
    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:participant.firstName attributes:attributes];
    NSLog(@"attString= %@", attString);
    NSLog(@"[attributes description]= %@", [attributes description]);

コンソールの出力は次のとおりです。

attributedParticipantName= Belinda{
    NSStrikethrough = 0;
 }
[attributes description]= {
    NSStrikethrough = 0;
}

そのため、辞書の説明が属性付き文字列に追加されています。なぜですか?

4

1 に答える 1

1

それがdescriptionメソッドのNSAttributedString実装方法です。デバッグに役立つように設計されているため、(プレーン テキストの) コンソールで文字列の属性を調べることができます。実際の文字列は、中括弧 ("Belinda") の前の部分です。属性なしで文字列だけを出力するには、log attString.string.

于 2013-03-23T11:58:27.853 に答える