Swicon 0.727

Swicon 0.727

测试已测试
语言语言 SwiftSwift
许可证 BSD
发布最后发布2015 年 7 月
SPM支持 SPM

Zhibo Wei 维护。



Swicon 0.727

  • 作者
  • Zhibo Wei

Swicon

使用超过 1600 个 FontAwesome 和 Google Material Icons 在您的 iOS 项目中以简单且空间高效的方式使用!

内置图标来自

安装

手动安装

将所有 Swift 文件和 ttf 文件复制到您的项目中

使用方法

  • 在您使用 Swicon 之前初始化它

    • (推荐) 在您的 AppDelegate 中添加一行
    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

图标名称映射

内置图标来自

  • Google Material Design Icons
    • 所有 Google Material Icons 都以“gm-”为前缀,后面跟着上述链接中真实的图标名称。例如,“gm-account_balance_wallet”是“account_balance_wallet”图标的名称。

  • FontAwesome
    • 所有 FontAwesome 图标都以前缀“fa-”开头,后面跟着 FontAwesome 的图标名称。例如,“fa-dashcube”是 FontAwesome 中“dashcube”图标的名称。

仅向 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

示例和截图

Swicon Screenshot

要求

iOS 8 或更高版本。 Swift 2 (Swift 1 仍然可以使用 <= 0.90 版本)

许可证

  • FontAwesome.ttf 文件许可根据 SIL OFL 1.1
  • GoogleMaterialDesignIcons 字体文件许可根据 CC-BY
  • Swicon 根据BSD许可