简体   繁体   English

将自定义字体添加到iOS中的UITextView中已解析的HTML内容时,斜体字体不起作用

[英]Italic font doesnt work when adding custom font to parsed HTML content in UITextView in iOS

I have a textview where I'm parsing and HTML content and it works fine. 我有一个textview,用于解析和HTML内容,并且工作正常。 But the tags marked italic doesn't work. 但是标记为斜体的标签不起作用。 I'm using a custom font. 我正在使用自定义字体。 Below is the sample code: 下面是示例代码:

NSString *messages = @"<b>Bold</b><br><i>Italic</i><p> <del>Deleted</del><p>List<ul><li>Coffee</li><li type='square'>Tea</li></ul><br><a href='URL'>Link </a>";

NSString *stringWithFont = [NSString stringWithFormat:@"<span style=\"font-family: OpenSans; font-size: 14\">%@</span>", messages];

NSAttributedString *attributedString = [[NSAttributedString alloc]
                                                initWithData: [stringWithFont dataUsingEncoding:NSUnicodeStringEncoding]
                                                options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
                                                documentAttributes: nil
                                                error: nil
                                                ];

_notificationTextView.attributedText = attributedString;

This is how it looks, note that the italic didn't work. 这就是它的外观,请注意斜体无效。

在此处输入图片说明

UPDATE 更新

Currently my project includes all Opensans font set like, regular, italic, bold, semibold etc. So, if I remove the light font or its reference from my project it seems to work. 当前,我的项目包括所有Opensans字体集,例如,常规,斜体,粗体,半粗体等。因此,如果我从项目中删除浅色字体或其参考,它似乎可以正常工作。 Looks like some kind of weird conflict with regular and light font. 看起来与常规字体和浅色字体有些奇怪的冲突。 Anybody has any ideas? 有人有什么想法吗?

It works for me. 这个对我有用。 Showing italic text. 显示斜体文本。 Use 采用

     self.txtView.attributedText=attributedString;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM