Using icon font in Swift
iOS 8.0+
To integrate ZHIconFontKit into your Xcode project using CocoaPods, specify it in your Podfile:
use_frameworks!
pod ‘ZHIconFontKit’if you are using swift 2.2:
pod 'ZHIconFontKit',:git => 'https://github.com/lacklock/ZHIconFontKit.git',:branch => '2.2'Just copy the files which under IconFontKit folder to your project
#Usage
1.make sure you font has been copy to bundle,check Build Phases:
![]()
2.after import ZHIconFontKit,register icon font:
IconFont.registerIconFontWithName("iconfont")3.create a enum rawValue type is Int and conform to UnicodeString protocol:
enum DXYIconFont: Int,UnicodeString{
case xxx = 59031
case yyy = 59027
}label.setIconFont(DXYIconFont.xxx, size: 40)button.setTitleIconFont(DXYIconFont.yyy, size: 50)imageView.image = UIImage.iconForIconFont(DXYIconFont.safari, size: 100, color: UIColor.purpleColor(), backgroundColor: UIColor.grayColor(), iconInset: UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0))If you are using in xib,just the same as using a cutom font.After set font as custom font,then paste icon from FontBook in atturibute pannel
![]()
Weibo : @没故事的卓同学