Font-Awesome-Swift 1.7.2

Font-Awesome-Swift 1.7.2

测试已测试
语言 SwiftSwift
许可协议 MIT
发布最新发布2017年11月
SwiftSwift 版本4.0
SPM支持 SPM

Patrik Vaberer 维护。




Font Awesome Swift

Font Awesome Swift

关注我:@vaberer

我喜欢明星标志。别忘了给这个超级方便的库加上星标。

增加了对 UISegmentedControlUITabbarItemUISliderUIStepperUITextField 的支持!

Font Awesome Swift iOS 库。不再使用图片图标。使用 Font Awesome Swift 库非常简单。查看演示应用,它展示了所有图标及其名称,或者直接访问 FontAwesome

要求

  • iOS 8.0+
  • Xcode 8

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖项管理器。

CocoaPods 0.36 版本增加了对 Swift 和嵌入式框架的支持。您可以使用以下命令进行安装

$ gem install cocoapods

要使用 CocoaPods 将 Font Awesome Swift 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Font-Awesome-Swift', '~> 1.7.2'

然后,执行以下命令

$ pod install

不要忘记将库导入到要使用此库的 Swift 文件中

import Font_Awesome_Swift

检查 swift-2.2swift-2.3swift-3 分支

手动方式

  1. FAIcon.swiftFontAwesome.ttf 文件复制到您的项目中
  2. 检查在项目中导入 FontAwesome.ttf,"项目" > "目标" > "复制 Bundle 资源"

使用方法

添加图标的一个简单方法。

UIImage

有关堆叠图像的信息,请参阅 堆叠图标

    UIImage.init(icon: .FATwitter, size: CGSize(width: 35, height: 35))
    
    // Change colors
    UIImage.init(icon: .FATwitter, size: CGSize(width: 35, height: 35), textColor: .red, backgroundColor: .black)
    
    // Stacked Images With Bigger Background
    UIImage.init(bgIcon: .FASquareO, bgTextColor: .white, topIcon: .FATwitter, topTextColor: .white, bgLarge: true)
    UIImage.init(bgIcon: .FACircle, bgTextColor: .black, topIcon: .FAFlag, topTextColor: .white, bgLarge: true)
    
    // Stacked Images With Smaller Background
    UIImage.init(bgIcon: .FACamera, bgTextColor: .black, topIcon: .FABan, topTextColor: .red, bgLarge: false)

    // Stacked Images With Bigger Background and Custom Size
    UIImage.init(bgIcon: .FASquare, bgTextColor: .black, topIcon: .FATerminal, topTextColor: .white, bgLarge: true, size: CGSize(width: 50, height: 50))

UIImageView

    imageView.setFAIconWithName(icon: .FATwitter, textColor: .blue, backgroundColor: .gray)

    imageView.setFAIconWithName(icon: .FATwitter, textColor: .blue)
    

UILabel

    labelName.FAIcon = .FAGithub

    labelName.setFAIcon(icon: .FAGithub, iconSize: 35)

    labelName.setFAText(prefixText: "follow me on ", icon: .FATwitter, postfixText: ". Thanks!", size: 25)

    // Bigger icon:
    labelName.setFAText(prefixText: "follow me on  ", icon: .FATwitter, postfixText: ". Thanks!", size: 25, iconSize: 30)

    labelName.setFAColor(.red)
    

UIButton

    buttonName.setFAIcon(icon: .FAGithub, forState: .normal)

    // Set icon size
    buttonName.setFAIcon(icon: .FAGithub, iconSize: 35, forState: .normal)

    buttonName.setFAText(prefixText: "follow me on ", icon: .FATwitter, postfixText: ". Thanks!", size: 25, forState: .normal)

    // Bigger icon
    buttonName.setFAText(prefixText: "follow me on ", icon: .FATwitter, postfixText: ". Thanks!", size: 25, forState: .normal, iconSize: 30)

    // Change color:
    buttonName.setFATitleColor(color: .red, forState: .normal))
    

UIBarButtonItem

    // Standard font size
    barName.FAIcon = .FAGithub

    // Custom font size
    barName.setFAIcon(icon: .FAGithub, iconSize: 35)

    barName.setFAText(prefixText: "follow me on ", icon: .FATwitter, postfixText: ". Thanks!", size: 25)

    barName.tintColor = .red

UITextField

    // Right View Icon
    textfield.setRightViewFAIcon(icon: .FASearch, rightViewMode: .always, textColor: .red, backgroundColor: .clear, size: nil)

    // Left View Icon
    textfield.setLeftViewFAIcon(icon: .FAPlus, leftViewMode: .always, textColor: .red, backgroundColor: .clear, size: nil)

UISegmentedControl

  segmentedControl.setFAIcon(icon: .FATwitter, forSegmentAtIndex: 0)
  

UIStepper

    stepper.setFABackgroundImage(icon: .FAGithub, forState: .normal)
    stepper.setFAIncrementImage(icon: .FABellO, forState: .normal)
    stepper.setFADecrementImage(icon: .FABellSlashO, forState: .normal)
    

UITabbarItem

  tabBarController?.tabBar.items?.first?.setFAIcon(.FATwitter)
  
  // Options to change selected and unselected color
  tabBarItem.setFAIcon(icon: .FATwitter, size: nil, textColor: .red, backgroundColor: .black, selectedTextColor: .yellow, selectedBackgroundColor: .white)
  
  // Options to change selected and unselected color with specific size
  tabBarItem.setFAIcon(icon: .FATwitter, size: CGSize(width: 35, height: 35), textColor: .red, backgroundColor: .black, selectedTextColor: .yellow, selectedBackgroundColor: .white)
  

UISlider

  // Change minimum or maximum value image
  slider.setFAMinimumValueImage(icon: .FABellSlashO)
  slider.setFAMaximumValueImage(icon: .FABellO)

  // change minimum or maximum value image with a specific size
  slider.setFAMinimumValueImage(icon: .FABellSlashO, customSize:  CGSize(width: 35, height: 35))
  slider.setFAMaximumValueImage(icon: .FABellO, customSize:  CGSize(width: 35, height: 35))
  

UIViewController

  // Change navigation title
  FATitle = .FATwitter
  

作者

Patrik Vaberer,[email protected]

许可协议

Font Awesome Swift 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件。