gpt4 book ai didi

swift - 如何在 swift 中使用 DTCoreText (DTWillFlushBlockCallBack)

转载 作者:行者123 更新时间:2023-11-28 08:04:09 28 4
gpt4 key购买 nike

        let callBackBlock:(DTHTMLElement) -> Void = { element in
for oneChildElement in element.childNodes {
guard let oneChildElement: DTHTMLElement = oneChildElement as? DTHTMLElement else {
return
}
if oneChildElement.displayStyle == .inline && oneChildElement.textAttachment.displaySize.height > 2.0 * oneChildElement.fontDescriptor.pointSize {
oneChildElement.displayStyle = .block;
oneChildElement.paragraphStyle.minimumLineHeight = element.textAttachment.displaySize.height;
oneChildElement.paragraphStyle.maximumLineHeight = element.textAttachment.displaySize.height;
}
}
}
let maxImageSize = CGSize(width: view.bounds.size.width - 20, height: view.bounds.size.height - 20)
return [NSTextSizeMultiplierDocumentOption: NSNumber(floatLiteral: 1.0),
DTMaxImageSize: NSValue(cgSize: maxImageSize),
DTDefaultTextColor: UIColor.white,
DTDefaultFontSize: NSNumber(floatLiteral: 15.0),
DTWillFlushBlockCallBack: callBackBlock]

我像这样在 swift 中使用 block ,但是 block 因 exc_bad_access 而崩溃

enter image description here

最佳答案

你可以像这样使用 DHTMLAttributedStringBuilder 来生成 attributedString

    let options = [String: Any]() # other options
let callBack: (DTHTMLElement?) -> Void = { element in
#do something
print(element)
}
if let builder = DTHTMLAttributedStringBuilder(html: data, options: options, documentAttributes: nil) {
builder.willFlushCallback = callBack
if let attribute = builder.generatedAttributedString() {
print(attribute)
}
}



关于swift - 如何在 swift 中使用 DTCoreText (DTWillFlushBlockCallBack),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45670092/

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