html - 如何启用按音节自动断字?
问题描述
我有 html 和 css 文件来在我的应用程序中显示我的教科书。我有这个代码来做到这一点:
let headerString = "<meta name=\"viewport\" content=\"initial-scale=1.1\" />"
do {
guard let filePath = Bundle.main.path(forResource: "\(readBookNumber)", ofType: "html")
else {
print ("File reading error")
return
}
var content = try String(contentsOfFile: filePath, encoding: .utf8)
let baseUrl = URL(fileURLWithPath: filePath)
content.changeHtmlStyle(font: "Iowan-Old-Style", fontSize: UserDefaults.standard.integer(forKey: "textSize"), fontColor: textColor)
webView.loadHTMLString(headerString+content, baseURL: baseUrl)
}
catch {
print ("File HTML error")
}
如何启用按音节自动断字?
我有:
在 2010 年 6 月
的全球
开发者大会上,
Apple 在开发者 工具国情咨文中
宣布
了 Xcode 的第 4版 。
我需要:
在 2010 年 6 月
的全球
开发者
大会上,Apple 在开发者 工具国情咨文 中
宣布
了 Xcode 的第 4 版 。
解决方案
您可以为此使用段落样式:
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .left
paragraphStyle.hyphenationFactor = 1.0
paragraphStyle.lineBreakMode = .byWordWrapping
let attributes = [
NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12)
]
let attributedText = NSAttributedString(string: inputText, attributes: attributes)
推荐阅读
- python-3.x - 无法导入模块“app”:没有名为“distutils.util”的模块-Dockerfile GDAL 和 geopandas python 3
- javascript - 在运行时将 React 组件子项添加到另一个 React 组件
- ansible - ansible --version 的不同输出
- html - 如何使用 CSS 删除复选框周围的空白(填充:0px)?
- c++ - 保持应该代表相同功能的同步 glsl 代码和 c++ 代码
- reactjs - Redux 工具包 RTK 查询突变没有得到返回数据
- java - 从 ubidots 获取实时数据到 android 应用程序
- python - 为什么 datetime 对象没有毫秒单位?
- c - 输入字母值时循环导致无限循环(C编程)
- postgresql - archlinux 将 postgresql 从 11 升级到 13:没有 /opt/pgsql-11/bin/ 文件夹