gpt4 book ai didi

Swift:填充 AutoreleasingUnsafeMutablePointer

转载 作者:搜寻专家 更新时间:2023-11-01 05:59:07 30 4
gpt4 key购买 nike

我是 DTCoreText,负责将 HTML 转换为属性文本。因为我想预先设置字体,而不是之后设置字体,因为那样会覆盖所有粗体、斜体等标签,所以我想在构造函数中设置文档属性。这个构造函数要我提供一个 AutoreleasingUnsafeMutablePointer,它或多或少似乎是一个 NSDictionary?在前面。有点。只是它不允许我以任何方式设置它。我试过 .memory,尝试以任何可能的方式转换字典,但它不接受任何数据。

    let font = UIFont.systemFontOfSize(12)
let data = info.desc?.dataUsingEncoding(NSUTF8StringEncoding)
let attributes: NSMutableDictionary? = NSMutableDictionary()
attributes!.setObject(font, forKey: NSFontAttributeName)
var attributeRef: AutoreleasingUnsafeMutablePointer<NSDictionary?> = AutoreleasingUnsafeMutablePointer.null()
NSMutableAttributedString(HTMLData: data, documentAttributes: nil)
//attributeRef = *attributeDict
let attributedString = NSMutableAttributedString(HTMLData: data, documentAttributes:attributeRef)
let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = NSLineBreakMode.ByWordWrapping;
let range = NSMakeRange(0, attributedString.length)
attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: range)
lblMessage.attributedText = attributedString

最佳答案

此时您不应该使用 DTCoreText; iOS 现在对此有本地调用。只需说 var dict = NSDictionary?() 并传递 &dict。这是示例代码:

let s = "<html><body><h1>Howdy</h1><p>Hello</p></body></html>"
let d = s.dataUsingEncoding(NSUTF16StringEncoding, allowLossyConversion: false)
var dict = NSDictionary?()
let att = NSAttributedString(data: d!, options: [
NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType
], documentAttributes: &dict, error: nil)
println(att!)
println(dict!)

您会发现这非常有效。这是字典:

BottomMargin = 72;
Converted = "-1";
DocumentType = NSHTML;
LeftMargin = 90;
PaperMargin = "UIEdgeInsets: {72, 90, 72, 90}";
PaperSize = "NSSize: {612, 792}";
RightMargin = 90;
TopMargin = 72;
UTI = "public.html";

但是,我通常传递 nil,因为我真正关心的第二个字典中没有返回任何内容。

关于Swift:填充 AutoreleasingUnsafeMutablePointer<NSDictionary?>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28571781/

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