Skip to content

Commit 25d3207

Browse files
authored
Merge pull request #9 from kgellci/master
Making PastelView more Objc compatible.
2 parents 0bd602d + ef9f423 commit 25d3207

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

Example/Pastel/ViewController.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ class ViewController: UIViewController {
2323
let pastelView = PastelView(frame: view.bounds)
2424

2525
// Custom Direction
26-
pastelView.startPoint = .bottomLeft
27-
pastelView.endPoint = .topRight
26+
pastelView.startPastelPoint = .bottomLeft
27+
pastelView.endPastelPoint = .topRight
2828

2929
// Custom Duration
3030
pastelView.animationDuration = 3.0
3131

3232
// Custom Color
33-
pastelView.setColors(colors: [UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
34-
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
35-
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
36-
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1.0),
37-
UIColor(red: 32/255, green: 158/255, blue: 255/255, alpha: 1.0),
38-
UIColor(red: 90/255, green: 120/255, blue: 127/255, alpha: 1.0),
39-
UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1.0)])
33+
pastelView.setColors([UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
34+
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
35+
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
36+
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1.0),
37+
UIColor(red: 32/255, green: 158/255, blue: 255/255, alpha: 1.0),
38+
UIColor(red: 90/255, green: 120/255, blue: 127/255, alpha: 1.0),
39+
UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1.0)])
4040

4141
pastelView.startAnimation()
4242
view.insertSubview(pastelView, at: 0)

Pastel/Classes/PastelView.swift

+20-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ open class PastelView: UIView {
1515
static let key = "ColorChange"
1616
}
1717

18-
public enum Point {
18+
@objc
19+
public enum PastelPoint: Int {
1920
case left
2021
case top
2122
case right
@@ -24,7 +25,6 @@ open class PastelView: UIView {
2425
case topRight
2526
case bottomLeft
2627
case bottomRight
27-
case custom(position: CGPoint)
2828

2929
var point: CGPoint {
3030
switch self {
@@ -36,15 +36,25 @@ open class PastelView: UIView {
3636
case .topRight: return CGPoint(x: 1.0, y: 0.0)
3737
case .bottomLeft: return CGPoint(x: 0.0, y: 1.0)
3838
case .bottomRight: return CGPoint(x: 1.0, y: 1.0)
39-
case .custom(let point):
40-
return point
4139
}
4240
}
4341
}
4442

4543
// Custom Direction
46-
open var startPoint: Point = .topRight
47-
open var endPoint: Point = .bottomLeft
44+
open var startPoint: CGPoint = PastelPoint.topRight.point
45+
open var endPoint: CGPoint = PastelPoint.bottomLeft.point
46+
47+
open var startPastelPoint = PastelPoint.topRight {
48+
didSet {
49+
startPoint = startPastelPoint.point
50+
}
51+
}
52+
53+
open var endPastelPoint = PastelPoint.bottomLeft {
54+
didSet {
55+
endPoint = endPastelPoint.point
56+
}
57+
}
4858

4959
// Custom Duration
5060
open var animationDuration: TimeInterval = 5.0
@@ -92,8 +102,8 @@ open class PastelView: UIView {
92102
fileprivate func setup() {
93103
gradient.frame = bounds
94104
gradient.colors = currentGradientSet()
95-
gradient.startPoint = startPoint.point
96-
gradient.endPoint = endPoint.point
105+
gradient.startPoint = startPoint
106+
gradient.endPoint = endPoint
97107
gradient.drawsAsynchronously = true
98108

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

108-
public func setColors(colors: [UIColor]) {
118+
public func setColors(_ colors: [UIColor]) {
109119
guard colors.count > 0 else { return }
110120
self.colors = colors
111121
}
112122

113-
public func addColor(color: UIColor) {
123+
public func addcolor(_ color: UIColor) {
114124
self.colors.append(color)
115125
}
116126

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ override func viewDidLoad() {
2020
let pastelView = PastelView(frame: view.bounds)
2121

2222
// Custom Direction
23-
pastelView.startPoint = .bottomLeft
24-
pastelView.endPoint = .topRight
23+
pastelView.startPastelPoint = .bottomLeft
24+
pastelView.endPastelPoint = .topRight
2525

2626
// Custom Duration
2727
pastelView.animationDuration = 3.0
2828

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

3838
pastelView.startAnimation()
3939
view.insertSubview(pastelView, at: 0)

0 commit comments

Comments
 (0)