gpt4 book ai didi

ios - UITextView 具有自定义字体和大小的 HTML 内容

转载 作者:行者123 更新时间:2023-11-30 10:57:55 25 4
gpt4 key购买 nike

我做了很多搜索,但无法弄清楚在 UITextView 中添加 html 内容的正确方法是什么。以下是我的代码。它没有设置正确的字体类型。

let htmlProfileString = "<html><head><style>body {font-family:\"SFProText-Regular\";font-size: 16px;color: #FFFFFF;text-decoration:none;}</style></head><body>" +
"This is content"
+ "</body></head></html>"

let htmlData = NSString(string: htmlProfileString).data(using: String.Encoding.unicode.rawValue)

let options = [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html]

let attributedString = try! NSAttributedString(data: htmlData!, options: options, documentAttributes: nil)
self.textView.attributedText = attributedString

最佳答案

要使用“系统”San Francisco 字体,请使用 -apple-system:

    let htmlProfileString = "<html><head><style>body {font-family:\"-apple-system\";font-size: 16px;color: #FFFFFF;text-decoration:none;}</style></head><body>" +
"This is content"
+ "</body></head></html>"

您还可以使用其他 css 字体样式:

font: -apple-system-body 
font: -apple-system-headline
font: -apple-system-subheadline
font: -apple-system-caption1
font: -apple-system-caption2
font: -apple-system-footnote
font: -apple-system-short-body
font: -apple-system-short-headline
font: -apple-system-short-subheadline
font: -apple-system-short-caption1
font: -apple-system-short-footnote
font: -apple-system-tall-body

关于ios - UITextView 具有自定义字体和大小的 HTML 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53731755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com