CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Dec 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✗ |
Maintained by zerozheng.
#描述
一个简单易用的 iconfont 字体库,swift3 版本。从此不用设计师切图(切图还是要的,只是少了适配的问题,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>
使用的时候可以使用内建字体库,也可以使用自定义的字体库。
使用默认内建字体库
先创建字体对象IconFont
实例
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'