@@ -29,6 +29,7 @@ import UIKit
29
29
30
30
@IBInspectable open var numberOfPages : Int = 0 {
31
31
didSet {
32
+ populateTintColors ( )
32
33
updateNumberOfPages ( numberOfPages)
33
34
self . isHidden = hidesForSinglePage && numberOfPages <= 1
34
35
}
@@ -83,6 +84,15 @@ import UIKit
83
84
setNeedsLayout ( )
84
85
}
85
86
}
87
+
88
+ open var tintColors : [ UIColor ] = [ ] {
89
+ didSet {
90
+ guard tintColors. count == numberOfPages else {
91
+ fatalError ( " The number of tint colors needs to be the same as the number of page " )
92
+ }
93
+ setNeedsLayout ( )
94
+ }
95
+ }
86
96
87
97
@IBInspectable open var currentPageTintColor : UIColor ? {
88
98
didSet {
@@ -122,6 +132,35 @@ import UIKit
122
132
}
123
133
}
124
134
135
+ func tintColor( position: Int ) -> UIColor {
136
+ if tintColors. count < numberOfPages {
137
+ return tintColor
138
+ } else {
139
+ return tintColors [ position]
140
+ }
141
+ }
142
+
143
+ open func insertTintColor( _ color: UIColor , position: Int ) {
144
+ if tintColors. count < numberOfPages {
145
+ setupTintColors ( )
146
+ }
147
+ tintColors [ position] = color
148
+ }
149
+
150
+ private func setupTintColors( ) {
151
+ tintColors = Array < UIColor > ( repeating: tintColor, count: numberOfPages)
152
+ }
153
+
154
+ private func populateTintColors( ) {
155
+ guard tintColors. count > 0 else { return }
156
+
157
+ if tintColors. count > numberOfPages {
158
+ tintColors = Array ( tintColors. prefix ( numberOfPages) )
159
+ } else if tintColors. count < numberOfPages {
160
+ tintColors. append ( contentsOf: Array < UIColor > ( repeating: tintColor, count: numberOfPages - tintColors. count) )
161
+ }
162
+ }
163
+
125
164
func animate( ) {
126
165
guard let moveToProgress = self . moveToProgress else { return }
127
166
@@ -159,3 +198,17 @@ import UIKit
159
198
fatalError ( " Should be implemented in child class " )
160
199
}
161
200
}
201
+
202
+ extension CHIBasePageControl {
203
+ internal func blend( color1: UIColor , color2: UIColor , progress: CGFloat ) -> UIColor {
204
+ let l1 = 1 - progress
205
+ let l2 = progress
206
+ var ( r1, g1, b1, a1) : ( CGFloat , CGFloat , CGFloat , CGFloat ) = ( 0 , 0 , 0 , 0 )
207
+ var ( r2, g2, b2, a2) : ( CGFloat , CGFloat , CGFloat , CGFloat ) = ( 0 , 0 , 0 , 0 )
208
+
209
+ color1. getRed ( & r1, green: & g1, blue: & b1, alpha: & a1)
210
+ color2. getRed ( & r2, green: & g2, blue: & b2, alpha: & a2)
211
+
212
+ return UIColor ( red: l1*r1 + l2*r2, green: l1*g1 + l2*g2, blue: l1*b1 + l2*b2, alpha: l1*a1 + l2*a2)
213
+ }
214
+ }
0 commit comments