Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Public initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardoCardoso committed May 31, 2017
1 parent 0c0839f commit caf1aab
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 49 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# Change Log

#### 0.x Releases
- `0.0.x` Releases - [0.0.1](#001)
- `0.0.x` Releases - [0.0.1](#001) | [0.0.2](#002)

---

## [0.0.2(https://github.com/LeonardoCardoso/NFDownloadButton/releases/tag/0.0.2)
Released on 2017-05-29.

#### Changed
- Public initializer.
- Changed by [Leonardo Cardoso](https://github.com/LeonardoCardoso).

## [0.0.1](https://github.com/LeonardoCardoso/NFDownloadButton/releases/tag/0.0.1)
Released on 2017-05-22.

Expand Down
5 changes: 5 additions & 0 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class ViewController: UIViewController {

super.viewDidAppear(animated)

let programmatically = NFDownloadButton(frame: CGRect(x: 10, y: 20, width: 50, height: 50))
programmatically.delegate = self
programmatically.addTarget(self, action: #selector(ViewController.changeState(_:)), for: .touchUpInside)
self.view.addSubview(programmatically)

iOSDownloadButton.delegate = self
watchOSDownloadButton.delegate = self
tvOSDownloadButton.delegate = self
Expand Down
2 changes: 1 addition & 1 deletion NFDownloadButton.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'NFDownloadButton'
s.version = '0.0.1'
s.version = '0.0.2'
s.license = { :type => "MIT", :file => "LICENSE" }
s.summary = 'Revamped Download Button'
s.homepage = 'https://github.com/LeonardoCardoso/NFDownloadButton'
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
| ![iOS](Images/iOS.gif) | ![watchOS](Images/watchOS.gif) | ![tvOS](Images/tvOS.gif) | ![macOS](Images/macOS.gif) |

[![Platform](https://img.shields.io/badge/platform-iOS-orange.svg)](https://github.com/LeonardoCardoso/NFDownloadButton#requirements-and-details)
[![CocoaPods](https://img.shields.io/badge/pod-v0.0.1-red.svg)](https://github.com/LeonardoCardoso/NFDownloadButton#cocoapods)
[![CocoaPods](https://img.shields.io/badge/pod-v0.0.2-red.svg)](https://github.com/LeonardoCardoso/NFDownloadButton#cocoapods)
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg)](https://github.com/LeonardoCardoso/NFDownloadButton#carthage)

> Revamped Download Button
Expand All @@ -31,7 +31,7 @@
$ gem install cocoapods
```

> CocoaPods 1.1.0+ is required to build NFDownloadButton 0.0.1+.
> CocoaPods 1.1.0+ is required to build NFDownloadButton 0.0.2+.
To integrate NFDownloadButton into your Xcode project using CocoaPods, specify it in your `Podfile`:

Expand All @@ -40,7 +40,7 @@ source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'NFDownloadButton', '~> 0.0.1'
pod 'NFDownloadButton', '~> 0.0.2'
```

Then, run the following command:
Expand All @@ -63,7 +63,7 @@ $ brew install carthage
To integrate NFDownloadButton into your Xcode project using Carthage, specify it in your `Cartfile`:

```ogdl
github "LeonardoCardoso/NFDownloadButton" ~> 0.0.1
github "LeonardoCardoso/NFDownloadButton" ~> 0.0.2
```

### Manually
Expand All @@ -72,12 +72,11 @@ If you prefer not to use either of the aforementioned dependency managers, you c

## Usage

You can use a `NFDownloadButton` on [Storyboards](#storyboard) or, if you want to do it programatically, you can create it just like you create a UIView:
You can use a `NFDownloadButton` on [Storyboards](#storyboard) or, if you want to do it programatically, you can create it just like you create a UIButton:

```swift
let downloadButton = NFDownloadButton(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
self.parentView.addSubview(downloadButton)
downloadButton.draw() // <- don't forget to call this function
```

`NFDownloadButton` has four states:
Expand Down Expand Up @@ -155,7 +154,7 @@ protocol NFDownloadButtonDelegate {
}
```

### Interface Builder / Storyboard
### Storyboard

Last but not least, you can customize `NFDownloadButton` properties right from Interface Builder or Storyboards.

Expand Down
86 changes: 46 additions & 40 deletions Sources/NFDownloadButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ open class Palette {
var downloadColor: UIColor = UIColor(red: 0.145, green: 0.439, blue: 0.733, alpha: 1.000)
var deviceColor: UIColor = UIColor(red: 0.145, green: 0.439, blue: 0.733, alpha: 1.000)

init(initialColor: UIColor? = nil, rippleColor: UIColor? = nil, buttonBackgroundColor: UIColor? = nil, downloadColor: UIColor? = nil, deviceColor: UIColor? = nil) {
public init(initialColor: UIColor? = nil, rippleColor: UIColor? = nil, buttonBackgroundColor: UIColor? = nil, downloadColor: UIColor? = nil, deviceColor: UIColor? = nil) {

self.initialColor = initialColor ?? self.initialColor
self.rippleColor = rippleColor ?? self.rippleColor
Expand Down Expand Up @@ -1115,7 +1115,7 @@ class NFDownloadButtonLayer: CALayer {

required init?(coder aDecoder: NSCoder) {

fatalError("init(coder:) has not been implemented")
super.init(coder: aDecoder)

}

Expand Down Expand Up @@ -1266,6 +1266,47 @@ open class NFDownloadButton: UIButton {

}

override open class var layerClass: AnyClass {

return NFDownloadButtonLayer.self

}

// MARK: - Initializers
override init(frame: CGRect) {

super.init(frame: frame)

draw()

}

public init(frame: CGRect, isDownloaded: Bool = false, style: NFDownloadButtonStyle = .iOS, palette: Palette = Palette()) {

super.init(frame: frame)

self.isDownloaded = isDownloaded
self.buttonStyle = style
self.palette = palette

draw()

}

required public init?(coder aDecoder: NSCoder) {

super.init(coder: aDecoder)

}

// MARK: - Lifecyle
override open func awakeFromNib() {

draw()

}


// MARK: - Properties
var keyPath: String = "toDownloadManipulable"
var palette: Palette = Palette()
Expand Down Expand Up @@ -1354,45 +1395,10 @@ open class NFDownloadButton: UIButton {

}

override open class var layerClass: AnyClass {

return NFDownloadButtonLayer.self

}

override init(frame: CGRect) {

super.init(frame: frame)

draw()

}

init(frame: CGRect, isDownloaded: Bool = false, style: NFDownloadButtonStyle = .iOS, palette: Palette = Palette()) {

super.init(frame: frame)

self.isDownloaded = isDownloaded
self.buttonStyle = style
self.palette = palette

}

required public init?(coder aDecoder: NSCoder) {

super.init(coder: aDecoder)

}

// MARK: - Lifecyle
override open func awakeFromNib() {

draw()

}

override open func draw(_ layer: CALayer, in ctx: CGContext) {

super.draw(layer, in: ctx)

guard
let layer: NFDownloadButtonLayer = layer as? NFDownloadButtonLayer,
let buttonStyle: NFDownloadButtonStyle = buttonStyle
Expand Down Expand Up @@ -1464,7 +1470,7 @@ open class NFDownloadButton: UIButton {
buttonStyle = buttonStyle ?? .iOS

needsDisplay()

}

func needsDisplay() {
Expand Down

0 comments on commit caf1aab

Please sign in to comment.