【发布时间】:2018-10-24 10:37:17
【问题描述】:
我在 TextView 中显示 HTML 数据,<ul> 或 <ol> 的填充空间超出了要求,但我无法从 HTML 端使用 CSS(我更愿意使用 CSS)调整填充/边距,有什么建议如何实现吗?
<html>
<head>
<style type="text/css">
body {
font-size: 14px;
font-family: -apple-system, Arial, sans-serif;
color: black;
margin-bottom: 0px;
padding-bottom: 0px;
line-height: 20px;
}
ul,
ol {
padding-left: 10px;
}
</style>
</head>
<body>
<p>Professionals are often vastly more comfortable solving analytical, convergent problems than those requiring more divergent thinking. In this article, Olivier Leclerc and Mihnea Moldoveanu share some strategies for stimulating truly novel thinking.
They introduce five "flexons," which can be thought of as "languages" for shaping problems that help you bring diverse perspectives to problem solving:</p>
<ul type="disc">
<li>Networks</li>
<li>Evolutionary</li>
</ul>
<ol>
<li>Decision-agent</li>
<li>System dynamics</li>
<li>Information-processing :
<ol>
<li>Decision-agent</li>
<li>System dynamics</li>
<li>Information-processing</li>
</ol>
</li>
</ol>
<ul type="disc">
<li>Networks :
<ul>
<li type="circle">Decision-agent</li>
<li type="circle">System dynamics</li>
</ul>
</li>
</ul>
</body>
</html>
这是 HTML,ul,ol {padding-left:10px;} 的 CSS 不适用。
将 HTML 字符串转换为 AttributeText 的功能
extension NSAttributedString {
convenience public init?(styled: String, textAlignment: NSTextAlignment = .center, color: UIColor = .black) {
guard let data = styled.data(using: String.Encoding.unicode) else {
return nil
}
do {
let string = try NSMutableAttributedString(data: data,
options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = textAlignment
string.addAttributes(
[NSAttributedStringKey.foregroundColor: color],
range: NSMakeRange(0, string.length)
)
self.init(attributedString: string.removingTrailingNewLine)
} catch {
return nil
}
}
var removingTrailingNewLine: NSAttributedString {
if string.hasSuffix("\n") {
return attributedSubstring(from: NSRange(location:0, length: length - 1))
}
return self
}
}
【问题讨论】:
-
请您添加一些代码。谢谢
-
@Adam 也添加了代码和屏幕截图。
-
所以您希望
ul和ol看起来像您添加的屏幕截图? -
这是它现在的样子,我希望左边距应该比现在显示的要小。
-
哦,只是做
padding-left: 0,这是边距而不是填充只是为了知道。所以将margin-left: 10px设为零。
标签: html ios css textview padding