Comments (8)
from fontawesome.swift.
you still can. just make sure you're using the unicode properly
// make sure to replace the contents of the curly braces with the icon you would like to use
myLabel.text = "\u{f0ac}"
from fontawesome.swift.
from fontawesome.swift.
Is there a particular reason you have to use unicode? The API has two features that may be more useful. Each FontAwesome icon has a rawValue: String
property, that matches the CSS codes for each particular icon. The second is UIImage.fontAwesomeIcon(code: String, style: textColor: size:)
that allows you to create a FontAwesome image from a CSS code. If you need to store and retrieve these codes, you can do something like this
let toStorage: String = icon.rawValue // icon being an instance of FontAwesome
store(toStorage, "identifier")
...
let fromStorage: String = retrieve("identifier")
let image = UIImage.fontAwesomeIcon(code: fromStorage, style: .regular, textColor: .black, size: CGSize(width: 10, height: 10))
from fontawesome.swift.
Well I am using a REST API that I don't own. They are sending the icon as a unicode char.
If you'd ask me I'd prefer using the CSS name. But in this case I don't have an option.
EDIT: To give some more context, they give me the unicode chars and I need to set them on TabBarItems. I was able to work around it by using the unicode chars on the TabBatItem title instead of the image. But that brings some problems with different screen scales. Being possible to go from Unicode char to UIImage would be great. The lack of this feature does not make the lib unusable to me. I just couldn't find a cleaner way to achieve this so far.
from fontawesome.swift.
Since this is coming from an API, this may warrant further investigation. However, for the time being, here's a solution that may work
let icon = resultFromApi.icon
// Here we will leverage the CaseIterable conformity of the FontAwesome enum
// Take note, if ONLY the unicode char is returned, and not the enclosing \u{}, you may need to
// interpolate the icon variable inside of a string, as in "\u{\(icon)}"
// Also note that in case the icon unicode is not found, you can provide a default.
// The `first` property will be optional
let fa = FontAwesome.allCases.filter { $0.unicode == icon }.first ?? FontAwesome.question
from fontawesome.swift.
Thank you, your suggestion does help me out.
One thing though, it's not enough to do \u{\(code)}
. The compiler cries.
I had to use something like this:
var fontAwesomeIconCode: String? {
let num = Int(strtoul(iconCode, nil, 16))
if let scalar = UnicodeScalar(num) {
return String(scalar)
}
return .none
}
from fontawesome.swift.
I was assuming in this case that what's returned is in Char format (i.e. f290
). In that case, to match it against something in the library as it stands, you'd have to use my format. If that's not the case, as it seems from what you're doing, you can either use your solution, which will only convert to String, or you can do something more elaborate like conversion to Char/String with interpolation, then filtering. Either way, this doesn't seem like a common problem, and I'm not sure I really want to tackle this problem just yet. It does seem to be solved though, so I'm closing this issue.
That being said, I am going to put something on the project board to investigate other ways to initialize.
from fontawesome.swift.
Related Issues (20)
- FontAwesome icon displayed as question mark - Swift
- Watch OS Support HOT 7
- icon + text = text becomes icon if text match icon name HOT 5
- Support coming for FontAwesome v5.13.1 HOT 15
- FA.swift showing strange icons after update HOT 4
- Cocoapods Says latest version 5.14.0 HOT 7
- used to work now completely broken HOT 2
- [iOS] Some images show question mark instead of actual icon HOT 3
- Retrieve image not work HOT 2
- update Enum file to include pro codes HOT 3
- xCode13 CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
- Navigation bar button with correct FA icon size
- FontAwsome Pro HOT 1
- Swift icons showing as Question Marks HOT 1
- Nil fontName leads to crash HOT 1
- FontAwesome 6.1 HOT 2
- Swift error HOT 1
- Request to bump iOS deployment target for Xcode 14.X build HOT 1
- New release? HOT 7
- Any support of Privacy Manifest? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fontawesome.swift.