Skip to content

Commit 827266f

Browse files
authored
Merge pull request #8 from ChiliLabs/feature/currentPageTintColor
add currentPageTintColor property
2 parents 49489a5 + 85b0b28 commit 827266f

12 files changed

+25
-42
lines changed

CHIPageControl.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'CHIPageControl'
3-
s.version = '0.0.2'
3+
s.version = '0.0.3'
44
s.summary = 'CHIPageControl is a set of cool animated page controls written in Swift to replace boring UIPageControl.'
55

66
s.ios.deployment_target = '8.0'

CHIPageControl/CHIPageControlAji.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ open class CHIPageControlAji: CHIBasePageControl {
4343
}
4444

4545
override func updateNumberOfPages(_ count: Int) {
46-
inactive.forEach() { $0.removeFromSuperlayer() }
4746
inactive = [CHILayer]()
4847
inactive = (0..<count).map {_ in
4948
let layer = CHILayer()
@@ -65,7 +64,7 @@ open class CHIPageControlAji: CHIBasePageControl {
6564
var frame = CGRect(x: x, y: y, width: self.diameter, height: self.diameter)
6665

6766
active.cornerRadius = self.radius
68-
active.backgroundColor = self.tintColor.cgColor
67+
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
6968
active.frame = frame
7069

7170
inactive.forEach() { layer in

CHIPageControl/CHIPageControlAleppo.swift

+4-9
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ open class CHIPageControlAleppo: CHIBasePageControl {
3333

3434
fileprivate var inactive = [CHILayer]()
3535

36-
fileprivate lazy var active: CHILayer = { [unowned self] in
37-
let layer = CHILayer()
38-
layer.backgroundColor = self.tintColor.cgColor
39-
layer.cornerRadius = self.radius
40-
self.layer.addSublayer(layer)
41-
return layer
42-
}()
36+
fileprivate var active: CHILayer = CHILayer()
4337

4438
required public init?(coder aDecoder: NSCoder) {
4539
super.init(coder: aDecoder)
@@ -50,13 +44,14 @@ open class CHIPageControlAleppo: CHIBasePageControl {
5044
}
5145

5246
override func updateNumberOfPages(_ count: Int) {
53-
inactive.forEach() { $0.removeFromSuperlayer() }
5447
inactive = [CHILayer]()
5548
inactive = (0..<count).map {_ in
5649
let layer = CHILayer()
5750
self.layer.addSublayer(layer)
5851
return layer
5952
}
53+
self.layer.addSublayer(active)
54+
6055
setNeedsLayout()
6156
self.invalidateIntrinsicContentSize()
6257
}
@@ -86,7 +81,7 @@ open class CHIPageControlAleppo: CHIBasePageControl {
8681
var frame = CGRect(x: x, y: y, width: self.diameter, height: self.diameter)
8782

8883
active.cornerRadius = self.radius
89-
active.backgroundColor = self.tintColor.cgColor
84+
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
9085
active.frame = frame
9186

9287
inactive.forEach() { layer in

CHIPageControl/CHIPageControlChimayo.swift

-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ open class CHIPageControlChimayo: CHIBasePageControl {
3232
return radius * 2
3333
}
3434

35-
fileprivate var active = CHILayer()
3635
fileprivate var inactive = [CHILayer]()
3736

3837
required public init?(coder aDecoder: NSCoder) {
@@ -49,7 +48,6 @@ open class CHIPageControlChimayo: CHIBasePageControl {
4948
}
5049

5150
override func updateNumberOfPages(_ count: Int) {
52-
inactive.forEach() { $0.removeFromSuperlayer() }
5351
inactive = [CHILayer]()
5452
inactive = (0..<count).map {_ in
5553
let layer = CHILayer()

CHIPageControl/CHIPageControlFresno.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ open class CHIPageControlFresno: CHIBasePageControl {
4646
}
4747

4848
override func updateNumberOfPages(_ count: Int) {
49-
elements.forEach() { $0.removeFromSuperlayer() }
5049
elements = [CHILayer]()
5150
elements = (0..<count).map {_ in
5251
let layer = CHILayer()
@@ -78,7 +77,7 @@ open class CHIPageControlFresno: CHIBasePageControl {
7877
}
7978

8079
if let active = elements.first {
81-
active.backgroundColor = self.tintColor.cgColor
80+
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
8281
active.borderWidth = 0
8382
}
8483

CHIPageControl/CHIPageControlJalapeno.swift

+2-8
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ open class CHIPageControlJalapeno: CHIBasePageControl {
3535

3636
fileprivate var inactive = [CHILayer]()
3737

38-
fileprivate lazy var active: CHILayer = { [unowned self] in
39-
let layer = CHILayer()
40-
layer.fillColor = self.tintColor.cgColor
41-
return layer
42-
}()
38+
fileprivate var active: CHILayer = CHILayer()
4339

4440
required public init?(coder aDecoder: NSCoder) {
4541
super.init(coder: aDecoder)
@@ -50,7 +46,6 @@ open class CHIPageControlJalapeno: CHIBasePageControl {
5046
}
5147

5248
override func updateNumberOfPages(_ count: Int) {
53-
inactive.forEach() { $0.removeFromSuperlayer() }
5449
inactive = [CHILayer]()
5550
inactive = (0..<count).map {_ in
5651
let layer = CHILayer()
@@ -59,7 +54,6 @@ open class CHIPageControlJalapeno: CHIBasePageControl {
5954
}
6055

6156
self.layer.addSublayer(active)
62-
6357
setNeedsLayout()
6458
self.invalidateIntrinsicContentSize()
6559
}
@@ -143,7 +137,7 @@ open class CHIPageControlJalapeno: CHIBasePageControl {
143137
layer.frame = frame
144138
frame.origin.x += self.diameter + self.padding
145139
}
146-
self.active.fillColor = self.tintColor.cgColor
140+
self.active.fillColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
147141
update(for: progress)
148142
}
149143

CHIPageControl/CHIPageControlJaloro.swift

+1-11
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ import UIKit
2727

2828
open class CHIPageControlJaloro: CHIBasePageControl {
2929

30-
override open var tintColor: UIColor! {
31-
didSet{
32-
active.backgroundColor = tintColor.cgColor
33-
inactive.forEach() {
34-
$0.backgroundColor = tintColor.withAlphaComponent(0.5).cgColor
35-
}
36-
}
37-
}
38-
3930
@IBInspectable open var elementWidth: CGFloat = 20 {
4031
didSet {
4132
setNeedsLayout()
@@ -60,7 +51,6 @@ open class CHIPageControlJaloro: CHIBasePageControl {
6051
}
6152

6253
override func updateNumberOfPages(_ count: Int) {
63-
inactive.forEach() { $0.removeFromSuperlayer() }
6454
inactive = [CHILayer]()
6555
inactive = (0..<count).map {_ in
6656
let layer = CHILayer()
@@ -83,7 +73,7 @@ open class CHIPageControlJaloro: CHIBasePageControl {
8373
var frame = CGRect(x: x, y: y, width: self.elementWidth, height: self.elementHeight)
8474

8575
active.cornerRadius = self.radius
86-
active.backgroundColor = self.tintColor?.cgColor
76+
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
8777
active.frame = frame
8878

8979
inactive.forEach() { layer in

CHIPageControl/CHIPageControlPaprika.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ open class CHIPageControlPaprika: CHIBasePageControl {
7979
}
8080

8181
if let active = elements.first {
82-
active.backgroundColor = self.tintColor.cgColor
82+
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
83+
active.borderWidth = 0
8384
}
8485

8586
min = elements.first?.frame

CHIPageControl/CHIPageControlPuya.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ open class CHIPageControlPuya: CHIBasePageControl {
4646
}
4747

4848
override func updateNumberOfPages(_ count: Int) {
49-
elements.forEach() { $0.removeFromSuperlayer() }
5049
elements = [CHILayer]()
5150
elements = (0..<count).map {_ in
5251
let layer = CHILayer()
@@ -78,7 +77,7 @@ open class CHIPageControlPuya: CHIBasePageControl {
7877
}
7978

8079
if let active = elements.first {
81-
active.backgroundColor = self.tintColor.cgColor
80+
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
8281
active.borderWidth = 0
8382
}
8483

@@ -112,6 +111,7 @@ open class CHIPageControlPuya: CHIBasePageControl {
112111
let offset = dist * percent
113112
guard let active = elements.first else { return }
114113
active.frame.origin.x = min.origin.x + offset
114+
active.borderWidth = 0
115115

116116
let index = page + 1
117117
guard elements.indices.contains(index) else { return }

CHIPageControl/Core/CHIBasePageControl.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ import UIKit
8383
setNeedsLayout()
8484
}
8585
}
86-
86+
87+
@IBInspectable open var currentPageTintColor: UIColor? {
88+
didSet {
89+
setNeedsLayout()
90+
}
91+
}
92+
8793
internal var moveToProgress: Double?
8894

8995
private var displayLink: CADisplayLink?

Example/Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ target 'Example' do
55
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
66
use_frameworks!
77

8-
pod 'CHIPageControl', :git => 'https://github.com/ChiliLabs/CHIPageControl.git'
8+
pod 'CHIPageControl', :path => '../'
99

1010
end

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ Just add the `CHIPageControl` folder to your project.
2525

2626
use [CocoaPods](https://cocoapods.org) with Podfile:
2727
``` ruby
28-
pod 'CHIPageControl', '~> 0.0.2'
28+
pod 'CHIPageControl', '~> 0.0.3'
2929
```
3030
### Carthage
3131

3232
use [Carthage](https://github.com/Carthage/Carthage) with Cartfile
3333
```ogdl
34-
github "ChiliLabs/CHIPageControl" ~> 0.0.2
34+
github "ChiliLabs/CHIPageControl" ~> 0.0.3
3535
```
3636

3737

@@ -45,6 +45,7 @@ let pageControl = CHIPageControlAji(frame: CGRect(x: 0, y:0, with: 100, height:
4545
pageControl.numberOfPages = 4
4646
pageControl.radius = 4
4747
pageControl.tintColor = .red
48+
pageControl.currentPageTintColor = .green
4849
pageControl.padding = 6
4950
```
5051
### Updating progress

0 commit comments

Comments
 (0)