Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is not working on interface builder. I see a question mark. Any help? #154

Closed
patchthecode opened this issue Sep 1, 2017 · 21 comments
Labels

Comments

@patchthecode
Copy link

patchthecode commented Sep 1, 2017

I dragged a UILabel unto storyBoard.
Then i changed the font to font awesome.
Then i pasted the icon -> 

It displays correctly on story board. But when i run the app, i am seeing a question mark.

Can you let me know the proper way to handle this on Interface builder/ Story board, with a UILabel?

@thii
Copy link
Owner

thii commented Sep 2, 2017

Probably the font was not loaded into memory before your storyboard was loaded. Do you have a sample project which reproduces this?

@james-ff
Copy link

james-ff commented Sep 21, 2017

For me this happens whenever the alpha of a previously working image changes or is set initally. See gif (buttons that turn to ? were clicked on which changes alpha by default, and the ones that don't appear to have an alpha are buttons that have isEnabled set to false which also sets an alpha). I should also say that this has not happened before and seems to be a new bug introduced in recent versions.
2017-09-21 12 43 49

@james-ff
Copy link

james-ff commented Sep 21, 2017

let barButtonItem = UIBarButtonItem.init(title: "", style: .plain, target: target, action: action)
barButtonItem.setTitleTextAttributes([NSAttributedStringKey.font: UIFont.fontAwesome(ofSize: iconSize)], for: .normal)
barButtonItem.title = "  \(String.fontAwesomeIcon(name: name))  "
barButtonItem.tintColor = color
return barButtonItem

@electic
Copy link

electic commented Sep 24, 2017

I have the same problem. I ended up just making them images :( I am using 1.2.0

@james-ff
Copy link

@thii Is this a quick fix?

@thii
Copy link
Owner

thii commented Sep 27, 2017

I'll try to have a look at it sometime this weekend.

@Maik639
Copy link
Collaborator

Maik639 commented Sep 27, 2017

Haven't tested it, but im pretty sure you have to set title text attributes for selected (and other) states too.
When selecting / pressing the button it changes to selected state and the title text attributes will be unset for that state.

@patchthecode
Copy link
Author

yea.. maybe for a UIButton. But it doesnt work for a UILabel.

@phoney
Copy link

phoney commented Sep 29, 2017

@james-ff @Maik639 This is a change in iOS 11 where setting textAttributes for themes or for controls requires setting the text attributes for both .normal and .highlighted.

@bradd-pktlzyer
Copy link

I had the same issue, shows in storyboard and ? in app. I walked the FontFamily and noticed font wasn't loading as I only used it in storyboard, I added a call to UIFont.fontAwesome(ofSize: 16) which installs the font via private FontLoad class. Worked after that.

@OlafAndreas
Copy link
Collaborator

Could someone confirm if in fact #170 provides a solution to this issue using: UIFont.loadFontAwesome() ?

@james-ff
Copy link

james-ff commented Jan 3, 2018

This has mostly been fixed for me, as mentioned by @phoney by applying attributes for multiple UIControlState enums, but the issue remains when a control is set to disabled (even though .disabled is used when setting the attributes). My guess is that the alpha of the BarButtonItem is causing the issue here, although when other enabled buttons are held down the alpha does not cause the icon to change to a [?] symbol.

barButtonItem.setTitleTextAttributes([NSAttributedStringKey.font: 
    UIFont.fontAwesome(ofSize: iconSize)], for: .normal)
barButtonItem.setTitleTextAttributes([NSAttributedStringKey.font: 
    UIFont.fontAwesome(ofSize: iconSize)], for: [.selected, .highlighted, .disabled, .reserved])

@james-ff
Copy link

james-ff commented Jan 9, 2018

@thii
Any progress on this issue?
To summarise my recent findings:

  • Holding down on a bar button doesn't cause the ? mark effect
  • Setting a bar button to disabled does
  • This occurs despite setting all of the UIControlStates as in my last comment
  • It seems that the UIControlStates addition fixes holding down, but not disabling a button

Many thanks for your hard work!

@OlafAndreas
Copy link
Collaborator

@james-ff
Are you using FontAwesomeBarButtonItem as a custom UIBarItem ?
If not, you should try that. I managed to reproduce what you're describing by not using FontAwesomeBarButtonItem and fixed it by setting the custom UIBarItem.

@james-ff
Copy link

james-ff commented Jan 12, 2018

@OlafAndreas
Could you provide sample code? I get the same outcome with the same setup of FontAwesomeBarButtonItem, and with just setting the title to cssCode I always get ?

@phoney
Copy link

phoney commented Jan 12, 2018

@james-ff Can you setTitleTextAttributes for each of the states separately, without using the option set? That's how I've done it.

When you tap on the barButtonItem, as shown in your video, the state of the barButtonItem changes to highlighted or selected, and apparently it doesn't know what to do in those cases.

@james-ff
Copy link

james-ff commented Jan 12, 2018

That worked!

let titleTextAttributes = [NSAttributedStringKey.font: UIFont.fontAwesome(ofSize: iconSize)]
        barButtonItem.setTitleTextAttributes(titleTextAttributes, for: .normal)
        barButtonItem.setTitleTextAttributes(titleTextAttributes, for: .selected)
        barButtonItem.setTitleTextAttributes(titleTextAttributes, for: .highlighted)
        barButtonItem.setTitleTextAttributes(titleTextAttributes, for: .disabled)

It seems that setting UIControlStates as an array of options has issues, which is a shame because it means less dry code. Would this be an issue with swift or this library?
Many Thanks @phoney!

@phoney
Copy link

phoney commented Jan 12, 2018

I think it's a UIKit issue and I think it's new in iOS 11. Never filed a bug though. Before that you could set the theme for .normal and it applied to all the states. I think it worked that way since the beginning.

devandanger added a commit to devandanger/CameraBarcodeReader that referenced this issue Jan 14, 2018
@alanscarpa
Copy link

alanscarpa commented Feb 5, 2018

This also displays a question mark instead of an icon when I assign this to the text of a UILabel let phoneIconString = String.fontAwesomeIcon(name: .phone) You need to update the label font to myLabel.font = UIFont.fontAwesome(ofSize: 16) and then things should work.

@stale
Copy link

stale bot commented Jul 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 10, 2019
@patchthecode
Copy link
Author

closing this issue.
Apple released glyphs. I'll use those instead of a lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants