FWIcon

@interface FWIcon : NSObject

字体图标抽象基类,子类需继承

Static

  • 图标加载器,访问未注册图标时会尝试调用并注册,block返回值为register方法class参数

    Declaration

    Objective-C

    @property (class, nonatomic, readonly) FWLoader<NSString *, Class> *_Nonnull sharedLoader;
  • 注册图标实现类,必须继承FWIcon,用于name快速查找,注意name不要重复

    Declaration

    Objective-C

    + (BOOL)registerClass:(nonnull Class)iconClass;
  • 指定名称和大小初始化图标对象

    Declaration

    Objective-C

    + (nullable FWIcon *)iconNamed:(nonnull NSString *)name size:(CGFloat)size;
  • 指定名称和大小初始化图标图像

    Declaration

    Objective-C

    + (nullable UIImage *)iconImage:(nonnull NSString *)name size:(CGFloat)size;
  • 安装图标字体文件,返回安装结果

    Declaration

    Objective-C

    + (BOOL)installIconFont:(nonnull NSURL *)fileURL;

Lifecycle

  • 根据字符编码和大小创建图标对象

    Declaration

    Objective-C

    - (nonnull instancetype)initWithCode:(nonnull NSString *)code
                                    size:(CGFloat)size;
  • 根据图标名称和大小创建图标对象

    Declaration

    Objective-C

    - (nullable instancetype)initWithName:(nonnull NSString *)name
                                     size:(CGFloat)size;
  • 自定义字体大小

    Declaration

    Objective-C

    @property (nonatomic) CGFloat fontSize;
  • 自定义背景色

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) UIColor *backgroundColor;
  • 自定义前景色

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) UIColor *foregroundColor;
  • 获取图标字符编码

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSString *_Nonnull characterCode;
  • 获取图标名称

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSString *_Nonnull iconName;
  • 返回图标字体

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) UIFont *_Nonnull iconFont;
  • 自定义图片偏移位置,仅创建Image时生效

    Declaration

    Objective-C

    @property (nonatomic) UIOffset imageOffset;
  • 返回字体相同大小的图标Image

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) UIImage *_Nonnull image;
  • 快速生成指定大小图标Image

    Declaration

    Objective-C

    - (nonnull UIImage *)imageWithSize:(CGSize)imageSize;

Attribute

  • 生成属性字符串

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSAttributedString *_Nonnull attributedString;
  • 设置图标属性,注意不要设置NSFontAttributeName为其他字体

    Declaration

    Objective-C

    - (void)setAttributes:(nonnull NSDictionary<NSAttributedStringKey, id> *)attrs;
  • 添加某个图标属性

    Declaration

    Objective-C

    - (void)addAttribute:(nonnull NSAttributedStringKey)name
                   value:(nonnull id)value;
  • 批量添加属性

    Declaration

    Objective-C

    - (void)addAttributes:(nonnull NSDictionary<NSAttributedStringKey, id> *)attrs;
  • 移除指定名称属性

    Declaration

    Objective-C

    - (void)removeAttribute:(nonnull NSAttributedStringKey)name;
  • 返回图标所有属性

    Declaration

    Objective-C

    - (nonnull NSDictionary<NSAttributedStringKey, id> *)attributes;
  • 返回图标指定属性

    Declaration

    Objective-C

    - (nullable id)attribute:(nonnull NSAttributedStringKey)name;

Protected

  • 所有图标名称=>编码映射字典,子类必须重写

    Declaration

    Objective-C

    + (nonnull NSDictionary<NSString *, NSString *> *)iconMapper;
  • 返回指定大小的图标字体,子类必须重写

    Declaration

    Objective-C

    + (nonnull UIFont *)iconFontWithSize:(CGFloat)size;