FontAwesomeSwift 1.9.3

FontAwesomeSwift 1.9.3

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2020年6月
SPM支持 SPM

Charles OderCharles Oder 维护。



  • Charles Oder

Build Status Cocoapods Version Swift Xcode Platform License

FontAwesomeSwift

iOS 的图标字体库。

安装

要求

  • Xcode 7+
  • iOS 8.0+
  • Swift 3.0+ 或 Objective-C

使用 Cocoapods 进行安装

在 Podfile 中添加 pod 'FontAwesomeSwift'

或者使用 subspecs 来只包含特定的字体

pod 'FontAwesomeSwift/FontAwesome'

pod 'FontAwesomeSwift/Ionicons'

pod 'FontAwesomeSwift/FoundationIcons'

pod 'FontAwesomeSwift/MaterialDesign'

pod 'FontAwesomeSwift/Octicons'

pod 'FontAwesomeSwift/Zocial'

运行 pod installpod update

使用方法

导入

Swift

import FontAwesomeSwift

Objective-C

#import <FontAwesomeSwift/FontAwesomeSwift-Swift.h>

创建图标

Swift

let icon: FASIcon = FASIonicons().checkmarkRoundIcon(size: 20)
let anotherIcon: FASIcon? = FASIonicons().icon(name: "ion-checkmark", size: 20)
let anotherIconFromCode: FASIcon = FASIonicons().icon(name: "\u{f122}", size: 20)
let greenIcon: FASIcon = FASIonicons().checkmarkRoundIcon(size: 20).color(color: UIColor.green)
let greenIconImage: UIImage? = FASIonicons().checkmarkRoundIcon(size: 20).color(color: UIColor.green).image
let greenIconAttributedString: NSAttributedString = FASIonicons().checkmarkRoundIcon(size: 20).color(color: UIColor.green).attributedString 
let iconImageWithGreenBackground: UIImage? = FASIonicons().checkmarkRoundIcon(size: 20).backgroundColor(color: UIColor.green).image
let paddedIconImage: UIImage? = FASIonicons().checkmarkRoundIcon(size: 20).padding(padding: 10).image
let offsetIconImage: UIImage? = FASIonicons().checkmarkRoundIcon(size: 20).offset(x: 20, y: 20).image

Objective-C

FASIcon *icon = [[FASIonicons new] iosInformationOutlineIconWithSize:20];
FASIcon *anotherIcon = [[FASIonicons new] iconWithName: @"ion-checkmark" size:20];
FASIcon *anotherIconFromCode = [[FASIonicons new] iconWithCode: @"\uf122" size:20];
FASIcon *greenIcon = [[[FASIonicons new] iosInformationOutlineIconWithSize:20] colorWithColor:[UIColor greenColor]];
UIImage *greenIconImage = [[[FASIonicons new] iosInformationOutlineIconWithSize:20] colorWithColor:[UIColor greenColor]].image;
NSAttributedString *greenIconAttributedString = [[[FASIonicons new] iosInformationOutlineIconWithSize:20] colorWithColor:[UIColor greenColor]].attributedString;
UIImage *greenBackgroundImage = [[[FASIonicons new] iosInformationOutlineIconWithSize:20] backgroundColorWithColor:[UIColor greenColor]].image;
UIImage *paddedIconImage = [[[FASIonicons new] iosInformationOutlineIconWithSize:20] paddingWithPadding: 10].image;
UIImage *offsetIconImage = [[[FASIonicons new] iosInformationOutlineIconWithSize:20] offsetWithX: 20 y: 20].image;

添加自定义字体

可以通过重写 FASFont 类并使用工厂重写属性:fontTypefontFamily 来声明字体族和类型,将自定义字体文件添加到项目中。

如果字体文件名与字体族名不同,可以通过重写 fontFileName 属性来声明这一点。

框架将在与重写的 FASFont 类关联的包中搜索。
如果字体文件位于不同的包中,可以重写 bundle 属性。

示例

public class CustomFont: FASFont {

   public override var fontFamily: String {
       return "CustomFontFamily"
   }
   
   public override var fontType: String {
       return "ttf"
   }
   
   public override var fontFileName: String {
       return "CustomFontFile"
   }

   public func customFontMethod(size: CGFloat) -> FASIcon {
       return FASIcon(font: font(size: size), iconCode: "\u{0001}")
   }
   
}

字体名称到字体编码映射

通过重写 allIcons 属性,使用 [name : code] 映射,允许客户端代码使用 icon(name: String, size: CGFloat) 方法创建字体图标。