NSFontAttributedString在XCode 6.1之前可用

发布于 2021-01-31 23:50:28

let timeFont = [NSFontAttributeName:UIFont(name: "Voyage", size: 20.0)]
var attrString3 = NSAttributedString("(Time)", attributes : timeFont); // <--- compiler error "Extra argument in call"

这段代码在xcode 6.0中可用,但是现在我已经升级到xcode
6.1,它不再起作用了,我不知道需要什么才能使其恢复工作。它说,还有一个额外的论点,但这是不正确的。我相信这与新的故障初始化程序有关,但是我尝试过的所有方法均无效。

关注者
0
被浏览
69
1 个回答
  • 面试哥
    面试哥 2021-01-31
    为面试而生,有面试问题,就找面试哥。

    Xcode 6.1随附有Swift
    1.1,该版本支持可能会失败的构造函数。UIFont初始化可能失败并返回nil。也可string:在创建时使用NSAttributedString

    if let font = UIFont(name: "Voyage", size: 20.0) {
        let timeFont = [NSFontAttributeName:font]
        var attrString3 = NSAttributedString(string: "(Time)", attributes : timeFont)
    }
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看