[英]FontAwesome icon displayed as question mark
I am trying to set the button text for the following : 我正在尝试将按钮文本设置为以下内容:
The first step I followed is to include the font file in the project. 我遵循的第一步是将字体文件包含在项目中。 I then referred it in the Info.plist.
然后,我在Info.plist中引用了它。
I copied the icon from the cheatsheet : 我从备忘单中复制了图标:
Then I set the font for the button in IB as follows : 然后我按如下所示在IB中设置按钮的字体:
As a result, I get a question mark on the button (both in IB and on running). 结果,我在按钮上(在IB中和正在运行中)都得到一个问号。
Just for cross checking, I set some other icon instead of this. 只是为了进行交叉检查,我设置了其他图标来代替它。 It worked fine.
工作正常。
Where could the mistake be ? 错误可能在哪里?
In IB set only the font name and size , in code use something like this 在IB中,仅设置字体名称和大小,在代码中使用类似以下内容
self.backBu.setTitle(String(format:"%C",0xf053), for: .normal);
replace f053
with unicode that you want , also make sure that target memberShip is checked for the font resource and you add it to info.plist 将
f053
替换为f053
的unicode,还请确保已检查目标memberShip的字体资源,并将其添加到info.plist
You are using the wrong font. 您使用了错误的字体。 The one you want is FontAwesome5FreeSolid (
fa-solid-900.ttf
). 您需要的是FontAwesome5FreeSolid(
fa-solid-900.ttf
)。
This works fine on my machine: 这在我的机器上工作正常:
let s = "\u{f362} Convert"
let ss = NSAttributedString(string: s, attributes:
[.font : UIFont(name:"FontAwesome5FreeSolid", size:17)!])
let b = UIButton(type: .system)
b.frame = CGRect(x: 40, y: 40, width: 200, height: 200)
b.setAttributedTitle(ss, for: .normal)
self.view.addSubview(b)
Result: 结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.