PrideChung / FontAwesomeKit

Icon font library for iOS. Currently supports Font-Awesome, Foundation icons, Zocial, and ionicons.
MIT License
2.81k stars 308 forks source link

iconWithIdentifier with swift #84

Open jpodcedensek opened 8 years ago

jpodcedensek commented 8 years ago

Hi, is there a way to use iconWithIdentifier in Swift code?

hebbian commented 8 years ago

No, there isn't last time I checked on latest installation from pod

jpodcedensek commented 8 years ago

I solved that in a dirty way with

let iconIdentifier = "iconId"
if iconIdentifier.containsString("fa-"){
    let iconCodes = FAKFontAwesome.allIcons() as NSDictionary
    if iconCodes.allKeysForObject(iconIdentifier.stringByReplacingOccurrencesOfString("fa-", withString: "")).count > 0{
        if let iconCode = iconCodes.allKeysForObject(iconIdentifier.stringByReplacingOccurrencesOfString("fa-", withString: ""))[0] as? String{
            iconLabel.attributedText = FAKFontAwesome(code: iconCode, size: 40).attributedString()
        }
    } else {
        print("Can't find FontAwesome icon for identifier ", iconIdentifier)
    }
}