HTML形式のタイトルを取得しています
<p><span style="color: #000000;"><strong>例</strong></span></p>
この HTML 文字列を UILabel に表示する必要があります。カラー コードとフォント サイズは、HTML に含まれているものと同じにする必要があります。HTML 文字列を NSString に変換すると、テキスト「例」のみが表示され、色は表示されません。
解決策はありますか?
事前にthnx
今まで、次の方法で NSAttributedString を使用しようとしていますが、この方法では HTML 全体が印刷されます。
UIFont *font = [UIFont systemFontOfSize:14.0];
UIFont *secondFont = [UIFont systemFontOfSize:10.0];
NSMutableDictionary *firstAttributes;
NSMutableDictionary *secondAttributes;
NSDictionary *firstAttributeFont = @{NSFontAttributeName:font};
NSDictionary *secondAttributeFont = @{NSFontAttributeName:secondFont};
[firstAttributes addEntriesFromDictionary:firstAttributeFont];
[secondAttributes addEntriesFromDictionary:secondAttributeFont];
[firstAttributes addEntriesFromDictionary:@{NSForegroundColorAttributeName:[UIColor clearColor]}];
[secondAttributes addEntriesFromDictionary:@{NSForegroundColorAttributeName:[UIColor clearColor]}];
NSString* completeString = [NSString stringWithFormat:@"%@",strTitle];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:completeString];
[attributedString setAttributes:firstAttributes range:[completeString rangeOfString:strTitle]];
// [attributedString setAttributes:secondAttributes range:[completeString rangeOfString:self.secondAttributeText]];
Cell.lbl_Title.attributedText = attributedString;