简体   繁体   English

显示为问号的FontAwesome图标

[英]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.

相关问题 UIPickerView 上显示的问号而不是 Xcode 10 上的 Realm 数据 - Question mark displayed on UIPickerView instead of Realm data on Xcode 10 iPhone在连接到Mac时显示问号(代替其图标) - iPhone shows Question mark (in place of its icon) on connecting to the Mac UiPickerview 值在 swift 中显示为问号(“?”) - 但在将其分配给文本框时获得正确的值 - UiPickerview values displayed as question mark (“?”)in swift - But getting the correct value while assigning it to a textBox 为什么我的 iOS 模拟器中有问号而不是 Material Design 图标? - Why do I have a question mark instead of a material design icon in my iOS simulator? NSPredicate 因问号而崩溃 - NSPredicate crashed with question mark 带问号的Sqlite查询 - Sqlite query with question mark iOS:在UIBarButtonItem和Button中添加带有标题的FontAwesome图标 - iOS: Append FontAwesome icon with title in UIBarButtonItem and Button Swift:使用FontAwesome图标作为UITabBarItem图像 - Swift: Use a FontAwesome icon as a UITabBarItem image FontAwesome图标仅在释放模式下崩溃 - FontAwesome icon crash only when release mode Swift:在 UIbutton 中将 fontawesome 图标与字符串混合 - Swift: Mix fontawesome icon with string in UIbutton
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM