You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
icon + text = text becomes icon if text match icon name #258
In my toolbar item, I have set everything according to the doc page, it was working fine because I was making my app in a different language than English. However, now my app requires English as an alternative language option and this problem occurred.
This is another problem I'm attempting to solve. When typing the name of an icon in English, the font auto-translates it to the appropriate icon, rather than just using Unicode. I have not yet been able to figure out why.
Are you initializing your UIBarButtonItem in Storyboard or inside a class?
This is another problem I'm attempting to solve. When typing the name of an icon in English, the font auto-translates it to the appropriate icon, rather than just using Unicode. I have not yet been able to figure out why.
Are you initializing your UIBarButtonItem in Storyboard or inside a class?
It is a UIBarButtonItem in the Storyboard, but used in a viewcontroller class.
I thought String.fontAwesomeIcon(name) is used to translate the icon into a string, but it seems to affect the entire title anyways with or without calling that function. It's almost as if it's matching anything that contains certain key words. I was trying to write "Routes Prev", it became: route Icon + "s Prev".
You're correct, and this is a source of investigation at the moment. I have yet to determine what it is about the font that causes actual text to be translated into an FA icon.
Currently, when using String.fontAwesomeIcon(name:), it's basically just the same as using FontAwesome.x_icon_name.unicode
Until I can solve this issue, my recommendations are:
Use NSAttributedString where available. UILabel and UIButton both have attributed title options.
Use only an icon otherwise
Here's a short code snippet to get you started with FA+NSAttributedString
letbutton=UIButton() // or link to one defined in your Storyboard
letlabel=UILabel()
// Note this MUST be Mutable for us to be able to apply an attribute
letstring=NSMutableAttributedString(string:"Sync "+.fontAwesomeIcon(name:.chevronRight))
// If your icon is the first char in the text, use range: NSRange(location: 0, length: 1)
string.addAttribute(.font, value:UIFont.fontAwesome(ofSize:18, style:.regular),
range:NSRange(location: string.length -1, length:1))
button.setAttributedTitle(string, for:.normal)
label.attributedText = string
Thanks for your reply, I did figure out a similar thing to yours for labels and buttons. However, UIBarButtonItem is a different story since it doesn't take attributed strings. Then I realized I can just stuff a button or label into the UIBarButtonItem...
So I figured a workaround for UIBarButtonItem, I didn't look into this problem until earlier since I had to do many more translations and this problem only happens at a few places for my project...I hate IOS localization lol.
It's a super roundabout way...But I don't have any better ideas rn
View Controller
letroutePreviewButton=UIBarButtonItem()! //linked from storyboard
letrouteButton=UIButton()
//Add your button target, users will touch this instead of the UIBarButtonItem now in my testing
routeButton.addTarget(self, action: #selector(navToRoutes), for:.touchUpInside)letrouteIconTextAttr= generalHelper.getFAIconWithText(name:.map, size:15, style:.solid, text:"Routes Prev.")
routeButton.setAttributedTitle(routeIconTextAttr, for:.normal)
routeButton.setAttributedTitle(routeIconTextAttr, for:.selected)
routeButton.sizeToFit()
routePreviewButton.customView = routeButton
So If anyone needs this. Here is a BarButtonItem that works with this library in its current state.
I'm still new to swift as I just came from Android development since our company is short-handed in the swift side. So there might be better ways to do this, but this works for me.
How to get button's action when pressed after linking your FABarButtonItem outlet
In your ViewConroller
barButtonItem.touchUpInside ={
//whatever you want to do
//If you need other interaction methods, modify FABarButtonItem and use "touchUpInside" as an example.
}
//Change title
setTitle(title: String)
//Change icon
setIcon(icon: FontAwesome)
//Change title and icon
setTitleAndIcon(title: String, icon: FontAwesome)
//Change color
setColor(color: UIColor)
It should also work with code init but it's not in my use case so I didn't care, you can modify my code to get it working if it's not already.
Activity
MatrixSenpai commentedon Jun 24, 2020
This is another problem I'm attempting to solve. When typing the name of an icon in English, the font auto-translates it to the appropriate icon, rather than just using Unicode. I have not yet been able to figure out why.
Are you initializing your
UIBarButtonItemin Storyboard or inside a class?Slodin commentedon Jun 24, 2020
It is a UIBarButtonItem in the Storyboard, but used in a viewcontroller class.
I thought String.fontAwesomeIcon(name) is used to translate the icon into a string, but it seems to affect the entire title anyways with or without calling that function. It's almost as if it's matching anything that contains certain key words. I was trying to write "Routes Prev", it became: route Icon + "s Prev".
MatrixSenpai commentedon Jun 25, 2020
You're correct, and this is a source of investigation at the moment. I have yet to determine what it is about the font that causes actual text to be translated into an FA icon.
Currently, when using
String.fontAwesomeIcon(name:), it's basically just the same as usingFontAwesome.x_icon_name.unicodeUntil I can solve this issue, my recommendations are:
UILabelandUIButtonboth have attributed title options.Here's a short code snippet to get you started with FA+NSAttributedString
Hope this helps!
Slodin commentedon Jun 26, 2020
Thanks for your reply, I did figure out a similar thing to yours for labels and buttons. However, UIBarButtonItem is a different story since it doesn't take attributed strings. Then I realized I can just stuff a button or label into the UIBarButtonItem...
So I figured a workaround for UIBarButtonItem, I didn't look into this problem until earlier since I had to do many more translations and this problem only happens at a few places for my project...I hate IOS localization lol.
It's a super roundabout way...But I don't have any better ideas rn
View Controller
GeneralHelper.getFAIconWithText
This approach still requires coders to adjust the button's appearance, but it's a basic start for me to at least get the bar buttons working.
Slodin commentedon Jul 11, 2020
So If anyone needs this. Here is a BarButtonItem that works with this library in its current state.
I'm still new to swift as I just came from Android development since our company is short-handed in the swift side. So there might be better ways to do this, but this works for me.
Usage:
How to get button's action when pressed after linking your FABarButtonItem outlet
In your ViewConroller
It should also work with code init but it's not in my use case so I didn't care, you can modify my code to get it working if it's not already.