Skip to content

Commit

Permalink
Merge pull request #9 from kgellci/master
Browse files Browse the repository at this point in the history
Making PastelView more Objc compatible.
  • Loading branch information
cruisediary committed May 18, 2017
2 parents 0bd602d + ef9f423 commit 25d3207
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
18 changes: 9 additions & 9 deletions Example/Pastel/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ class ViewController: UIViewController {
let pastelView = PastelView(frame: view.bounds)

// Custom Direction
pastelView.startPoint = .bottomLeft
pastelView.endPoint = .topRight
pastelView.startPastelPoint = .bottomLeft
pastelView.endPastelPoint = .topRight

// Custom Duration
pastelView.animationDuration = 3.0

// Custom Color
pastelView.setColors(colors: [UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1.0),
UIColor(red: 32/255, green: 158/255, blue: 255/255, alpha: 1.0),
UIColor(red: 90/255, green: 120/255, blue: 127/255, alpha: 1.0),
UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1.0)])
pastelView.setColors([UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1.0),
UIColor(red: 32/255, green: 158/255, blue: 255/255, alpha: 1.0),
UIColor(red: 90/255, green: 120/255, blue: 127/255, alpha: 1.0),
UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1.0)])

pastelView.startAnimation()
view.insertSubview(pastelView, at: 0)
Expand Down
30 changes: 20 additions & 10 deletions Pastel/Classes/PastelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ open class PastelView: UIView {
static let key = "ColorChange"
}

public enum Point {
@objc
public enum PastelPoint: Int {
case left
case top
case right
Expand All @@ -24,7 +25,6 @@ open class PastelView: UIView {
case topRight
case bottomLeft
case bottomRight
case custom(position: CGPoint)

var point: CGPoint {
switch self {
Expand All @@ -36,15 +36,25 @@ open class PastelView: UIView {
case .topRight: return CGPoint(x: 1.0, y: 0.0)
case .bottomLeft: return CGPoint(x: 0.0, y: 1.0)
case .bottomRight: return CGPoint(x: 1.0, y: 1.0)
case .custom(let point):
return point
}
}
}

// Custom Direction
open var startPoint: Point = .topRight
open var endPoint: Point = .bottomLeft
open var startPoint: CGPoint = PastelPoint.topRight.point
open var endPoint: CGPoint = PastelPoint.bottomLeft.point

open var startPastelPoint = PastelPoint.topRight {
didSet {
startPoint = startPastelPoint.point
}
}

open var endPastelPoint = PastelPoint.bottomLeft {
didSet {
endPoint = endPastelPoint.point
}
}

// Custom Duration
open var animationDuration: TimeInterval = 5.0
Expand Down Expand Up @@ -92,8 +102,8 @@ open class PastelView: UIView {
fileprivate func setup() {
gradient.frame = bounds
gradient.colors = currentGradientSet()
gradient.startPoint = startPoint.point
gradient.endPoint = endPoint.point
gradient.startPoint = startPoint
gradient.endPoint = endPoint
gradient.drawsAsynchronously = true

layer.insertSublayer(gradient, at: 0)
Expand All @@ -105,12 +115,12 @@ open class PastelView: UIView {
colors[(currentGradient + 1) % colors.count].cgColor]
}

public func setColors(colors: [UIColor]) {
public func setColors(_ colors: [UIColor]) {
guard colors.count > 0 else { return }
self.colors = colors
}

public func addColor(color: UIColor) {
public func addcolor(_ color: UIColor) {
self.colors.append(color)
}

Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ override func viewDidLoad() {
let pastelView = PastelView(frame: view.bounds)

// Custom Direction
pastelView.startPoint = .bottomLeft
pastelView.endPoint = .topRight
pastelView.startPastelPoint = .bottomLeft
pastelView.endPastelPoint = .topRight

// Custom Duration
pastelView.animationDuration = 3.0

// Custom Color
pastelView.setColors(colors: [UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1.0),
UIColor(red: 32/255, green: 158/255, blue: 255/255, alpha: 1.0),
UIColor(red: 90/255, green: 120/255, blue: 127/255, alpha: 1.0),
UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1.0)])
pastelView.setColors([UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1.0),
UIColor(red: 32/255, green: 158/255, blue: 255/255, alpha: 1.0),
UIColor(red: 90/255, green: 120/255, blue: 127/255, alpha: 1.0),
UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1.0)])

pastelView.startAnimation()
view.insertSubview(pastelView, at: 0)
Expand Down

0 comments on commit 25d3207

Please sign in to comment.