我正在尝试使用此https://github.com/thii/FontAwesome.swift包在我的应用中实现FontAwesome图标。我正确地遵循了所有说明,但出于某种原因,当我试图在我的导航栏中实现一个图标时:
let attributes = [NSFontAttributeName: UIFont.fontAwesome(ofSize: 20)] as [String: Any]
mapButton.setTitleTextAttributes(attributes, for: .normal)
mapButton.title = String.fontAwesomeIcon(name: .globe)
我收到错误:Ambiguous use of 'fontAwesome(name:)'
,xcode说它找到了这两个候选人:
/// Get a FontAwesome icon string with the given icon name.
///
/// - parameter name: The preferred icon name.
/// - returns: A string that will appear as icon with FontAwesome.
public static func fontAwesomeIcon(name: FontAwesome) -> String {
return name.rawValue.substring(to: name.rawValue.characters.index(name.rawValue.startIndex, offsetBy: 1))
}
/// Get a FontAwesome icon string with the given CSS icon code. Icon code can be found here: http://fontawesome.io/icons/
///
/// - parameter code: The preferred icon name.
/// - returns: A string that will appear as icon with FontAwesome.
public static func fontAwesomeIcon(code: String) -> String? {
guard let name = self.fontAwesome(code: code) else {
return nil
}
return self.fontAwesomeIcon(name: name)
}
这个包中的演示文件工作正常,所以我很困惑为什么我的代码不起作用。有没有办法选择默认运行xcode的候选者?
答案 0 :(得分:0)
当我尝试在我的导航栏中实现图标时
究竟是什么mapButton
?它是UIBarButtonItem吗?因为如果是,你的代码应该编译得很好。我试过这个:
let mapButton = UIBarItem() // my code
// the rest is _exactly_ your code!
let attributes = [NSFontAttributeName: UIFont.fontAwesome(ofSize: 20)] as [String: Any]
mapButton.setTitleTextAttributes(attributes, for: .normal)
mapButton.title = String.fontAwesomeIcon(name: .globe)
它编译得很好。
模糊地使用
fontAwesome(name:)
真的?如果您要编写fontAwesome(name:)
,您肯定会收到编译错误,因为术语fontAwesome
与术语fontAwesomeIcon
不同。但在这种情况下,您的代码和错误消息不会一起出现!无论如何,如果我刻意犯了这个错误,我得到的错误信息是一个不同的错误。