在 Swift 4 中没有更多上下文属性文本的表达式类型不明确 [英] Type of expression is ambiguous without more context attributed text in Swift 4

查看:83
本文介绍了在 Swift 4 中没有更多上下文属性文本的表达式类型不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在属性中使用了相同的字体:,它给出了上述错误

I am using a font in the same in attribute: , it is giving above error

do {
        let myAttribute = [ NSAttributedStringKey.font: UIFont(name: "Chalkduster", size: 18.0)! ]


        let attrStr = try NSAttributedString(data: ("Some String HTML".data(using: String.Encoding.unicode, allowLossyConversion: false)!)!,options: [.documentType: NSAttributedString.DocumentType.html,
                                                       .characterEncoding: String.Encoding.utf8.rawValue],
                                             documentAttributes: nil,attributes: myAttribute)
        self.NoAccessMessage.font = UIFont(name: "Arial", size: 16.0)
        self.NoAccessMessage.attributedText = attrStr

    } catch let error {

    }

请检查是否需要任何帮助

Please check if any help is required

推荐答案

您将两种不同的东西结合在一起.您可以要么将属性应用于字符串读取一些HTML.两者都不是.

You are combining two different things. You can either apply an attribute to a string or read some HTML. Not both.

也许你的意思是:

let myAttribute = [ NSAttributedStringKey.font: UIFont(name: "Chalkduster", size: 18.0)! ]
let attrStr = NSAttributedString(string: "howdy there", attributes: myAttribute)

或者你的意思是:

let html = "<p>howdy <b>there</b></p>"
let htmldata = html.data(using: .utf8)
let attrStr = try NSAttributedString(data: htmldata!, options: [.documentType : NSAttributedString.DocumentType.html], documentAttributes: nil)

下定决心.

这篇关于在 Swift 4 中没有更多上下文属性文本的表达式类型不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆