NFDownloadButton 0.0.6

NFDownloadButton 0.0.6

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布最新发布2018年9月
SPM支持 SPM

Leonardo Cardoso维护。



NFDownloadButton

iOS watchOS tvOS macOS

Platform CocoaPods Carthage Compatible

重制的下载按钮

要求

  • iOS 8.0+
  • Swift 4.2+
  • Xcode 10.0+

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它:

$ gem install cocoapods

需要 CocoaPods 1.1.0+ 来构建 NFDownloadButton 0.0.6+。

要将 NFDownloadButton 集成到您的 Xcode 项目中使用 CocoaPods,在您的 Podfile 中指定它:

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

pod 'NFDownloadButton', '~> 0.0.6'

然后,运行以下命令:

$ pod install

Carthage

Carthage 是一款去中心化的依赖管理工具,它自动对 Cocoa 应用添加框架。

您可以使用以下命令使用 Homebrew 安装 Carthage

$ brew update
$ brew install carthage

要使用 Carthage 将 NFDownloadButton 集成到您的 Xcode 项目中,请在您的 Cartfile 中指定它

github "LeonardoCardoso/NFDownloadButton" ~> 0.0.6

手动集成

如果您不希望使用上述依赖管理器之一,您可以将 NFDownloadButton 手动集成到项目中。

使用方法

您可以在 Storyboards 上使用 NFDownloadButton,或者如果您想以编程方式实现,可以像创建 UIButton 一样创建它

let downloadButton = NFDownloadButton(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
self.parentView.addSubview(downloadButton)

NFDownloadButton 有四个状态

状态 1:待下载 状态 2:准备下载 状态 3:准备就绪的下载 状态 4:已下载
first second third fourth

您可以通过以下方式在不同的状态之间切换

self.downloadButton.downloadState = .toDownload || .willDownload || .readyToDownload || .downloaded

当按钮处于 .readyToDownload 状态时,按钮将等待您上传其实时进度。您可以这样做

self.downloadButton.downloadPercent = 0.5

当此值达到 1.0 时,downloadState 将自动更改为 .downloaded

默认下载

您可以选择将按钮默认标记为已下载。所有状态都将被 Downloaded 状态覆盖,且不会执行动画。要这样做,只需在其构造函数中添加 isDownloaded,或者随时设置它。

NFDownloadButton(frame: CGRect(x: 0, y: 0, width: 50, height: 50), isDownloaded: true)
downloadButton.isDownloaded = true

样式

NFDownloadButton 拥有四种不同风格的设备: iOSwatchOStvOSmacOS。因此,您可以自定义最终结果。此选项仅可在构造函数中使用。

NFDownloadButton(frame: CGRect(x: 0, y: 0, width: 50, height: 50), isDownloaded: true,
    style: .iOS)
iOS watchOS tvOS macOS
iOS watchOS tvOS macOS

调色板

您还可以在构造函数中自定义按钮的颜色。

NFDownloadButton(
    frame: wrapView.frame,
    isDownloaded: true,
    style: .iOS,
    palette: Palette(
        initialColor: UIColor?,
        rippleColor: UIColor?,
        buttonBackgroundColor: UIColor?,
        downloadColor: UIColor?,
        deviceColor: UIColor?
    )
)

palette

代理

您可以通过实现协议来监控状态的更改

protocol NFDownloadButtonDelegate {

    func stateChanged(button: NFDownloadButton, newState: NFDownloadButtonState)

}

故事板

最后但同样重要的是,您可以直接从 Interface Builder 或 Storyboard 中自定义 NFDownloadButton 的属性。

storyboard

许可证

NFDownloadButton 以 MIT 许可证发布。有关详细信息,请参阅 LICENSE

关注我以获取最新更新