0
UILabel
にNSAttributedString
を設定しているセルを含む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;
}
何かの理由で、何らかの理由で自動的にデフォルトのシステムフォント(サイズ17)に戻りますが、回避するのは簡単です。 –