FontAwesomeKit.Swift
支持
Swift 4.2 & iOS 8.0+
FontAwesome 4.7.0
支持 Storyboard。
安装
CocoaPods
- 在你的 Podfile 中添加
pod 'FontAwesomeKit.Swift'
。 - 运行
pod install
或者pod update
。 导入 FontAwesomeKit_Swift
手动
- 下载完整文件。
- 将 FontAwesomeKit 文件夹拖到您的项目中。
示例
FontAwesomeKit.Swift
。
在 Storyboard 中使用 - 将自定义类设置为
FontAwesomeButton
或FontAwesomeLabel
- 在属性检查器 中为
FontAwesomeLabel
设置 Unicode 字符串,或为FontAwesomeButton
设置normal
、highlighted
、selected
、disabled
的 Unicode 字符串,例如f107
或0xf107
// 所有 awesome Unicode --> http://fontawesome.io/cheatsheet/
FontAwesomeKit.Swift
与字符串。
使用 let str1 = String.fontAwesome(undefined: 0xf107)
let str2 = String.fontAwesome(awesomeType: .github)
let attrs = [NSFontAttributeName: UIFont(fontSize: 32)]
let attrStr1 = NSAttributedString(string: str1)
let attrStr2 = NSAttributedString(string: str2)
The attrStr1 will get icon. The attrStr2 will get icon.
FontAwesomeKit.Swift
与 UILabel。
使用 let label = UILabel()
label.text = .apple
label.font = UIFont(fontSize: 100)
/// text : FontAwesomeType.
FontAwesomeKit.Swift
和 UIButton。
使用 let button = UIButton(type: .custom)
button.setTitle(.gift, for: .normal)
/// type : The fontAwesome type, and you don’t need to ‘setImage’ or ‘setBackgroundImage’
/// state : The state that uses the specified title. The possible values are described in UIControlState.
button.titleLabel?.font = UIFont(fontSize: 50)
FontAwesomeKit.Swift
和 UIImage。
使用 let image1 = UIImage(awesomeType: .github)
/// fontSize : The fontSize you can give, default is 80.
/// tintColor : The UIImage filled color you get, default is UIColor.lightGray.
let image2 = UIImage(awesomeType: .github, size: 30.0, color: UIColor.black)
FontAwesomeKit.Swift
和 UINavigationBarItem。
使用 let rightItem = UIBarButtonItem(awesomeType: .github, style: .plain, target: nil, action: nil)
let leftItem = UIBarButtonItem(awesomeType: .github, size: 24, style: .plain, target: nil, action: nil)
/// fontSize : The font size, default is ‘24.0’
/// awesomeType : FontAwsomeType
授权
遵循MIT 许可协议
感谢
- FontAwesome Unicode 列表。 来自 fontawesome.io
- 最新版本 (版本 4.7.0) 的 FontAwesome.otf 套件