我在
Swift 2.0中有AutoLayout的奇怪问题
self.webView = WKWebView() self.view.addSubview(self.webView!) var viewBindingsDict: NSMutableDictionary = NSMutableDictionary() viewBindingsDict.setValue(self.webView,forKey: "webView") self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|",options: 0,metrics: nil,views: viewBindingsDict)) self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[webView]|",views: viewBindingsDict))
我收到错误:
'String' is not convertible to 'StringLiteralConvertible'
对于“H:| [webView] |”和“V:| [webView] |”
我不知道我是否缺少一些东西
你应该把你的viewBindigsDict改成
原文链接:https://www.f2er.com/swift/319640.htmlvar viewBindingsDict = [String: AnyObject]() viewBindingsDict["webView"] = webView
如在注释中所建议的,并且在格式选项中,您不能使用0,而是:
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|",options: NSLayoutFormatOptions(rawValue: 0),views: viewBindingsDict))
或者更简单,因为@MartinR建议:
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|",options: [],views: viewBindingsDict))