- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码无法读取 <strong>
标记,我无法将其设为粗体:
let txt = "`<p><em>The first day of your <strong>Kerala tour itinerary</strong> starts with a trip along the winding roads to the beautiful hill station of Munnar</em></p>\r\n<p>`Your holiday to the mesmerizing Munnar starts with `a `transfer from Cochin. Enjoy the picturesque hill-station as you drive through the serpentine roads surrounded by lush green hills. En route, visit the beautiful Cheeyappara, Valara, and Attukadu waterfalls and the spice plantations, as part of your `<strong>3 day Kerala tourism package itinerary</strong>.` Upon arrival, check-in to the hotel and relax for a while. Later, enjoy local sightseeing and marvel at the beauty all around. Mark an end to the first day of `<strong>Munnar tour package</strong>` with a comfortable overnight stay at the hotel.` </p>\r\n<p><strong>Distance from Cochin to Munnar:</strong> 130 km (approx.)<br /><strong>Travel Time:</strong> 4 hours (approx.) </p>`"
let dataValue = txt.data(using: String.Encoding.unicode,
allowLossyConversion: true)!
let optionaArr = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType]
let attrStr = try! NSAttributedString(data: dataValue,
options: optionaArr,
documentAttributes: nil)
txtView.attributedText = attrStr
除了标签,我可以读取所有标签,例如 <p>, <em>
和所有。提前致谢。
最佳答案
下面的代码适用于我(swift 4.1 和 Xcode 9.3)
let txt = "`<p><em>The first day of your <strong>Kerala tour itinerary</strong> starts with a trip along the winding roads to the beautiful hill station of Munnar</em></p>\r\n<p>`Your holiday to the mesmerizing Munnar starts with `a `transfer from Cochin. Enjoy the picturesque hill-station as you drive through the serpentine roads surrounded by lush green hills. En route, visit the beautiful Cheeyappara, Valara, and Attukadu waterfalls and the spice plantations, as part of your `<strong>3 day Kerala tourism package itinerary</strong>.` Upon arrival, check-in to the hotel and relax for a while. Later, enjoy local sightseeing and marvel at the beauty all around. Mark an end to the first day of `<strong>Munnar tour package</strong>` with a comfortable overnight stay at the hotel.` </p>\r\n<p><strong>Distance from Cochin to Munnar:</strong> 130 km (approx.)<br /><strong>Travel Time:</strong> 4 hours (approx.) </p>`"
let dataValue = txt.data(using: String.Encoding.unicode,
allowLossyConversion: true)!
let attrStr = try! NSAttributedString(data: dataValue,
options: [.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil)
txtView.attributedText = attrStr
关于swift - 无法使用 NSHTMLTextDocumentType 读取 <strong> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49690879/
我正在尝试使用此 NSAttributedString 在 UITextView 中显示 HTML 文本: [[NSAttributedString alloc] initWithData:[html
在我的应用程序中,我想在 UILabel 中显示文本。我使用 HTML 将文本存储在我的数据库中,以动态地从我的应用程序中的文本中获取。我实际上使用这个(Swift 3.2,iOS 8+): if l
我正在 UITextView 中显示一些 HTML 内容。内容有要点。这些项目符号是使用无序列表 ( ) 创建的,但每个项目符号都是重复的。 我创建了 NSAttributedString 喜欢 l
我的代码无法读取 标记,我无法将其设为粗体: let txt = "`The first day of your Kerala tour itinerary starts with a trip al
我正在尝试使用 NSHTMLTextDocumentType 格式化 UITextView 中的文本。 UITextView 位于 PageViewController 的页面/VC 上。 一切正常,
打电话 NSAttributedString * as = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding
当使用 NSHTMLTextDocumentType 从 HTML 创建 NSAttributedString 时,我发现即使在最后一段。这是在 UILabel 中显示的最后一段文本下方添加不需要的填
我是一名优秀的程序员,十分优秀!