TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | BSD |
ReleasedLast Release | Jul 2015 |
SPMSupports SPM | ✗ |
Maintained by Zhibo Wei.
Use 1600+ icons from FontAwesome and Google Material Icons in your iOS project in an easy and space-efficient way!
The built-in icons are from
Copy all Swift files and ttf files into your project
Initialize Swicon before you use it:
import Swicon
.............
Swicon.instance.loadAllAsync()
OR
import Swicon
.............
Swicon.instance.loadAllSync()
//Now you can start using it
Swicon.instance.getUIImage(......)
YOU ONLY NEED TO DO THE INITIALIZATION ONCE AFTER YOUR APP STARTS
Get iconic string or generate an image from the icon:
//Get NSAttributedString, the "gm-games" is the name of Google Material Design's "games" icon
let iconicString = Swicon.instance.getNSMutableAttributedString("gm-games", fontSize: 10)
//Set it to label, to button, or whatever place you like
label.attributedText = iconicString
//Get UIImage, "fa-heart" is the "Heart" icon from FontAwesome
let iconicImage = Swicon.instance.getUIImage("fa-heart", iconSize: 100, iconColour: UIColor.blueColor(), imageSize: CGSizeMake(200, 200))
//Set it to UIImageView
imgView.image = iconicImage
The built-in icons are from
And just give Swicon the icon name you want to render and Swicon will handle everything else for you.
Let’s say you have your own icon font(which can reduce the app size compare to including the resource images for different sizes) you want to be displayed in your iOS project, you only need to:
//BEFORE you call Swicon init
//The font name prefix you want to use. For example, if you set it to "custom" and Swicon see an icon name start with "custom-", then it will know it's a custom font.
let customFontPrefix = "custom"
//Copy the ttf font file into your project and give Swicon the font file name (WITHOUT the ".ttf" extension)
let fontFileName = "custom_font" //Then Swicon will try to load the font from "custom_font.ttf" file
//The Font File Name, the fontName of your font. (The font name after you install the ttf into your system)
let fontName = "Custom"
//The icon name/value mapping dict ([FONT_NAME: FONT_UNICODE_VALUE])
let iconNameValueMappingDict = ["custom-1":"\u{f000}",...]
//Add custom font to Swicon
Swicon.instance.addCustomFont(prefix: customFontPrefix, fontFileName: fontFileName, fontName: fontName, fontIconMap: iconNameValueMappingDict)
//Then init Swicon
Swicon.instance.loadAllAsync() //Or Sync, depends on your needs
iOS 8 or later. Swift 2 (Swift 1 can still use the version <= 0.90)