使用超过 1600 个 FontAwesome 和 Google Material Icons 在您的 iOS 项目中以简单且空间高效的方式使用!
内置图标来自
将所有 Swift 文件和 ttf 文件复制到您的项目中
在您使用 Swicon 之前初始化它
import Swicon
.............
Swicon.instance.loadAllAsync()
OR
import Swicon
.............
Swicon.instance.loadAllSync()
//Now you can start using it
Swicon.instance.getUIImage(......)
你只需在您的应用程序启动后执行一次初始化
获取图标字符串或从图标生成图像
//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
内置图标来自
仅向 Swicon 提供要渲染的图标名称,Swicon 将为您处理其他所有操作。
假设您有自己的图标字体(与包含不同尺寸的资源图像相比,可以减少应用程序大小)并希望在您的 iOS 项目中显示,您只需
//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 或更高版本。 Swift 2 (Swift 1 仍然可以使用 <= 0.90 版本)