IconFontKit 2.1.2

IconFontKit 2.1.2

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT 协议
Release最后发布2016年12月

Elf Sundae 维护。



IconFontKit 为 iOS 开发提供了一个方便的工具包,用于使用图标字体。

Sample Explorer Selector

安装

  • 使用 pod 'IconFontKit/Core' 仅安装 IFIcon 抽象类。
  • 使用 pod 'IconFontKit' 安装所有图标包。
  • 使用 pod 'IconFontKit/{Font Identifier}' 安装特定的图标包,例如 pod 'IconFontKit/FontAwesome'

用法

  • 图标可以通过三种方式创建:如同 @"\uf179"代码、如同 IFFAApple类型、如同 @"fa-apple"标识符
    推荐使用 代码类型 方式。

      IFFontAwesome *faIcon = [IFFontAwesome iconWithCode:@"\uf17b" fontSize:20.0];
      IFIonicons *ionIcon = [IFFontAwesome iconWithType:IFIIWifi fontSize:20.0];
      IFOcticons *octIcon = [IFOcticons iconWithIdentifier:@"octicon-gift" fontSize:20.0];
  • IFIcon 使用 NSAttributedString 作为后端,并提供了一些访问属性的方法,例如

    - (NSDictionary *)attributes;
    - (void)addAttribute:(NSString *)name value:(id)value;
    - (void)removeAttribute:(NSString *)name;
    - (void)setAttributes:(NSDictionary *)attributes;
  • 您可以使用 -[IFxxxIcon imageWithSize:]+[IFxxxIcon imageWithType:color:...] 等等方式创建图标图像。

    UIImage *image = [IFFontAwesome imageWithType:IFOIArrowRight color:nil imageSize:CGSizeMake(30, 30)];
  • 使用 +[IFxxxIcon fontWithSize:] 获取类型为 UIFont 的图标字体实例。

  • [UIImage if_imageWithStackedIcons:imageSize:] 可以将多个图标堆叠到一个图像中。

    /**
     * Draws the IFIcons on an image.
     * These icons will be centered horizontally and vertically by default.
     * You can set the `drawingPositionAdjustment` property to adjust drawing offset for each icon.
     *
     * @param icons The icons to be drawn. The first icon will be drawn on the bottom and the last icon will be drawn on the top.
     * @param imageSize Height and width for the generated image.
     *
     * @return An image with the icons.
     */
    + (UIImage *)if_imageWithStackedIcons:(NSArray <IFIcon *>*)icons imageSize:(CGSize)imageSize;

    例如

    IFFontAwesome *container = [IFFontAwesome iconWithType:IFFASquareO fontSize:100.0 color:[UIColor colorWithWhite:0.88 alpha:1.0]];
    container.drawingPositionAdjustment = UIOffsetMake(0, 4);
    IFFontAwesome *forbidden = [IFFontAwesome iconWithType:IFFABan fontSize:70.0 color:[[UIColor redColor] colorWithAlphaComponent:0.6]];
    IFFontAwesome *usbIcon = [IFFontAwesome iconWithType:IFFAUsb fontSize:50];
    
    UIImage *stackedImage = [UIImage if_imageWithStackedIcons:@[container, usbIcon, forbidden] imageSize:CGSizeMake(100, 100)];

使用自定义图标字体

  • 要使用自己的图标字体,请继承 IFIcon 并实现 + (NSURL *)fontFileURL 方法。
  • 如果字体名称与 fontFileURL 的文件名不同,则需要实现 + (NSString *)fontName 方法。
  • 如果您想要使用 标识符 方式创建图标,也需要实现 + (NSDictionary *)allIcons 方法。
  • 您自定义字体的图标类型是该图标的 unicode 十六进制值。例如,图标代码 \uf100 的类型是 0xf100
  • 注意:您可以使用 IcoMoon appFontelloFontastic 或其他出色的服务生成图标字体。
  • 在 "IconFontKitExample/MyFontIcons" 中查看示例。

    // MyFontIcons.h
    
    #import <IconFontKit/IFIcon.h>
    
    typedef NS_ENUM(IFIconType, MyFontIconsType) {
        MFFacebookSquared   = 0xa100,
        MFChat              = 0xa101,
        MFEmoHappy          = 0xa102,
        MFThumbsUp          = 0xa103,
        MFThumbsUpAlt       = 0xa104,
        MFLinkExt           = 0xa105,
        MFVolumeUp          = 0xa106,
        MFCogAlt            = 0xa107,
        MFCode              = 0xa108,
    };
    
    @interface MyFontIcons : IFIcon
    @end
    // MyFontIcons.m
    
    #import "MyFontIcons.h"
    
    @implementation MyFontIcons
    
    + (NSURL *)fontFileURL {
        return [[[NSBundle mainBundle] resourceURL] URLByAppendingPathComponent:@"myfonticons.ttf"];
    }
    
    // Optional becase the font name is the same as the filename of font.
    //+ (NSString *)fontName {
    //    return @"myfonticons";
    //}
    
    + (NSDictionary *)allIcons {
        return @{
                 @"facebook-squared":  @"\ua100",
                 @"chat":              @"\ua101",
                 @"emo-happy":         @"\ua102",
                 @"thumbs-up":         @"\ua103",
                 @"thumbs-up-alt":     @"\ua104",
                 @"link-ext":          @"\ua105",
                 @"volume-up":         @"\ua106",
                 @"cog-alt":           @"\ua107",
                 @"code":              @"\ua108",
                 };
    }
    @end

内置图标包

字体标识符 版本 图标数量 字体大小 许可证 描述
FontAwesome 4.7.0 675 135 KB SIL OFL 1.1 Font Awesome
Octicons 4.3.0 172 45 KB SIL OFL 1.1 GitHub 的图标
FoundationIcons 3.0 283 57 KB ? Foundation Icon Fonts 3
Ionicons 2.0.1 733 189 KB MIT 协议 用于 Ionic Framework 的专用图标字体。
MaterialDesignIcons 1.6.50 1650 236 KB SIL OFL 1.1 Material Design Icons
魅影图标 2.0.0 304 80 KB SIL OFL 1.1 魅影图标
材质图标 2.2.3 932 128 KB CC-BY 4.0 由谷歌为材质设计制作的。
社交按钮 1.2.0 102 26 KB MIT 协议 社交按钮
Typicons 2.0.7 336 100 KB SIL OFL 1.1
开源图标 1.1.1 223 28 KB SIL OFL 1.1 开源图标是Iconic的兄弟。
Metraz图标 1.0 300 63 KB 免费使用 metro风格图标
Meteocons 1.0 47 18 KB 免费使用 一组天气图标
MFG实验室图标集 1.0 186 56 KB SIL OFL 1.1 MFG实验室图标集
LineariconsFree 1.0.0 170 56 KB CC BY-SA 4.0 Linearicons Free版本
IcoMoonFree 1.0.0 491 95 KB CC BY 4.0或GPL IcoMoon免费包
HawconsFilled 1.0 517 107 KB 免费使用 Hawcons渐变风格,包括文档、体育、天气、表情符号、手势、文件类型等图标。
HawconsStroke 1.0 518 138 KB 免费使用 Hawcons线条风格,包括文档、体育、天气、表情符号、手势、文件类型等图标。
Dashicons 3.8 234 42 KB GPLv2 _dashicons是WordPress管理员的官方图标字体。
Linea 1.0 716 125 KB CCBY 由Dario Ferrando设计的一个免费轮廓图标集。
Entypo 1.0 411 76 KB CC BY-SA 4.0 Entypo+是一个免费的高级质图标的第三版。
Themeify图标 1.0 352 79 KB 免费使用 手工绘制的图标,灵感来自Apple iOS 7。
StreamlineFree v2 100 38 KB 许可证 Streamline免费包,免费iOS 8矢量图标
stroke7Icons 1.2 202 58 KB 免费使用 来自Pixeden的一系列iOS 7灵感的细线条图标。
devicons 1.8.0 171 147 KB MIT 协议 为开发者设计的图标字体。
LigatureSymbols 2.11 239 84 KB SIL OFL 1.1 Kazuyuki Motoyama的Ligature Symbols
Dripicons 1.0 95 21 KB 免费使用 由[Amit Jakhu](http://amitjakhu.com)提供的一个完全免费的矢量线图字体。
OpenWeb图标 1.4.0 97 40 KB SIL OFL 1.1 OpenWeb图标
Genericons 3.4.1 147 22 KB GPLv2 设计得简洁、简单,符合通用美学。
MapIcons 3.0.0 175 48 KB SIL OFL 1.1 与Google Maps配合使用的图标字体。
WeatherIcons 2.0.10 219 100 KB SIL OFL 1.1 基于天气、海事和气象的图标
Evil图标 1.8.0 70 15 KB MIT 协议 一个简单、干净的SVG图标包,代码支持Rails、Sprockets、Node.js、Gulp、Grunt和CDN。

致谢

IconFontKit受到了FontAwaoneKit的启发。

授权许可

IconFontKit可在MIT许可下使用。有关更多信息,请参阅LICENSE文件。

注意:每个图标字体都有其自己的许可协议。