测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可 | MIT |
发布最后发布 | 2017年12月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由 zerozheng 维护。
#描述
一个简单易用的 iconfont 字体库,Swift 3 版本。从此不用设计师切图(切图仍然需要,只是减少了适配问题,1x、2x、3x …),同时app也变得更轻量。
#使用
本框架内建了一个小型字体库,共有八十个图标,如果想要查看其中的字体(图标),可以在 **浏览器**
中打开 demo 工程下 fontHtmlSource
文件夹中的三个 html
文件查看,不仅可以看到 unicode
,还可以找到 字体标识
。如图:
<img src=“https://github.com/zerozheng/IconFontSwift/blob/master/demo01.jpeg” alt=“IconFontSwift”/ width = 250> <img src=“https://github.com/zerozheng/IconFontSwift/blob/master/demo02.png” alt=“IconFontSwift”/ width = 250> <img src=“https://github.com/zerozheng/IconFontSwift/blob/master/demo03.png” alt=“IconFontSwift”/ width = 250>
使用时可以使用内建字体库,也可以使用自定义的字体库。
使用默认内建字体库
首先创建一个 UILabel 实例
guard let myfont = IconFont.init() else {
return
}
self.topLabel.font = UIFont(name: myfont.fontName, size: 50)
self.topLabel.textColor = UIColor.purple
self.topLabel.text = "myfont.icons["time"]"
self.imageView.image = UIImage.zz.image(withText: myfont.icons["phone"], fontName: myfont.fontName, fontSize: 200, imageSize: 200, color: UIColor.green, backGroundColor: UIColor.purple)
//异步
self.bottomImageView.zz.asyncImage(withText: myfont.icons["delete_fill"], fontName: myfont.fontName, fontSize: 100, imageSize: 100, color: UIColor.green, backGroundColor: UIColor.purple)
自定义字体库
先定义一个 IconFont
的子类,然后填写自定义字体库的信息,例如:
class MyFont: IconFont {
//**注意**:字体名字,它跟字体文件名是不一样的
override var fontName: String {
return "iconfont"
}
//字体文件名
override var fileName: String {
return "ZZIconFont"
}
override var filePath: String {
return Bundle.main.path(forResource: fileName, ofType: extensionName) ?? ""
}
override var extensionName: String {
return "ttf"
}
override var icons: [String : String] {
return ["cart":"\u{e6af}", "delete_fill":"\u{e6a6}"]
}
}
然后创建一个自定义的字体对象 MyFont
实例
guard let myfont = MyFont.init() else {
return
}
self.topLabel.font = UIFont(name: myfont.fontName, size: 50)
self.topLabel.textColor = UIColor.purple
self.topLabel.text = "myfont.icons["time"]"
self.imageView.image = UIImage.zz.image(withText: myfont.icons["phone"], fontName: myfont.fontName, fontSize: 200, imageSize: 200, color: UIColor.green, backGroundColor: UIColor.purple)
//异步
self.bottomImageView.zz.asyncImage(withText: myfont.icons["delete_fill"], fontName: myfont.fontName, fontSize: 100, imageSize: 100, color: UIColor.green, backGroundColor: UIColor.purple)
pod 'IconFontSwift', '~> 0.0.2'