2016-10-15 6 views
0

UILabelNSAttributedStringを設定しているセルを含むUITableViewがあります。 NSAttributedStringには、<b>%@</b> by <b>%@</b>を使用してHTML太字のセクションがあり、最初のパスで正しくレンダリングされますが、セルが再び呼び出されると、文字列全体が個々のセクションではなく太字で表示されます。再利用可能なデキュー時に属性付き文字列フォントの書式が変更される

この機能を使用してNSAttributedStringを準備します。これを解決する

- (NSAttributedString *)attributedStringForString:(NSString *)string forFont:(UIFont *)font { 
    NSLog(@"Get attributed string"); 
    string = [string stringByAppendingString:[NSString stringWithFormat:@"<style>body{font-family: '%@'; font-size:%fpx; color:#000000;}</style>", 
               font.fontName, 
               font.pointSize]]; 

    NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}; 
    NSAttributedString *labelString = [[NSAttributedString alloc] initWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:options documentAttributes:nil error:nil]; 

    return labelString; 
} 

答えて

2

カップルの方法:

1)

カスタムUITableViewCellので、あなたはprepareForReuse実装する必要があります:あなたがデキュー後

-(void)prepareForReuse{ 
    [super prepareForReuse]; 

    // Then Reset here back to default values that you want. 
    self.label.font = [UIFont systemFontOfSize: 12.0f]; 
} 

2)

あなたのテーブルビューのセルをcellForRowAtIndexPathの方法で実行することができます

+0

何かの理由で、何らかの理由で自動的にデフォルトのシステムフォント(サイズ17)に戻りますが、回避するのは簡単です。 –

関連する問題