Skip to content

Commit

Permalink
Merge pull request #8 from ChiliLabs/feature/currentPageTintColor
Browse files Browse the repository at this point in the history
add currentPageTintColor property
  • Loading branch information
chili-ios authored Mar 20, 2017
2 parents 49489a5 + 85b0b28 commit 827266f
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 42 deletions.
2 changes: 1 addition & 1 deletion CHIPageControl.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'CHIPageControl'
s.version = '0.0.2'
s.version = '0.0.3'
s.summary = 'CHIPageControl is a set of cool animated page controls written in Swift to replace boring UIPageControl.'

s.ios.deployment_target = '8.0'
Expand Down
3 changes: 1 addition & 2 deletions CHIPageControl/CHIPageControlAji.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ open class CHIPageControlAji: CHIBasePageControl {
}

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

active.cornerRadius = self.radius
active.backgroundColor = self.tintColor.cgColor
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
active.frame = frame

inactive.forEach() { layer in
Expand Down
13 changes: 4 additions & 9 deletions CHIPageControl/CHIPageControlAleppo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ open class CHIPageControlAleppo: CHIBasePageControl {

fileprivate var inactive = [CHILayer]()

fileprivate lazy var active: CHILayer = { [unowned self] in
let layer = CHILayer()
layer.backgroundColor = self.tintColor.cgColor
layer.cornerRadius = self.radius
self.layer.addSublayer(layer)
return layer
}()
fileprivate var active: CHILayer = CHILayer()

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

override func updateNumberOfPages(_ count: Int) {
inactive.forEach() { $0.removeFromSuperlayer() }
inactive = [CHILayer]()
inactive = (0..<count).map {_ in
let layer = CHILayer()
self.layer.addSublayer(layer)
return layer
}
self.layer.addSublayer(active)

setNeedsLayout()
self.invalidateIntrinsicContentSize()
}
Expand Down Expand Up @@ -86,7 +81,7 @@ open class CHIPageControlAleppo: CHIBasePageControl {
var frame = CGRect(x: x, y: y, width: self.diameter, height: self.diameter)

active.cornerRadius = self.radius
active.backgroundColor = self.tintColor.cgColor
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
active.frame = frame

inactive.forEach() { layer in
Expand Down
2 changes: 0 additions & 2 deletions CHIPageControl/CHIPageControlChimayo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ open class CHIPageControlChimayo: CHIBasePageControl {
return radius * 2
}

fileprivate var active = CHILayer()
fileprivate var inactive = [CHILayer]()

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

override func updateNumberOfPages(_ count: Int) {
inactive.forEach() { $0.removeFromSuperlayer() }
inactive = [CHILayer]()
inactive = (0..<count).map {_ in
let layer = CHILayer()
Expand Down
3 changes: 1 addition & 2 deletions CHIPageControl/CHIPageControlFresno.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ open class CHIPageControlFresno: CHIBasePageControl {
}

override func updateNumberOfPages(_ count: Int) {
elements.forEach() { $0.removeFromSuperlayer() }
elements = [CHILayer]()
elements = (0..<count).map {_ in
let layer = CHILayer()
Expand Down Expand Up @@ -78,7 +77,7 @@ open class CHIPageControlFresno: CHIBasePageControl {
}

if let active = elements.first {
active.backgroundColor = self.tintColor.cgColor
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
active.borderWidth = 0
}

Expand Down
10 changes: 2 additions & 8 deletions CHIPageControl/CHIPageControlJalapeno.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ open class CHIPageControlJalapeno: CHIBasePageControl {

fileprivate var inactive = [CHILayer]()

fileprivate lazy var active: CHILayer = { [unowned self] in
let layer = CHILayer()
layer.fillColor = self.tintColor.cgColor
return layer
}()
fileprivate var active: CHILayer = CHILayer()

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

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

self.layer.addSublayer(active)

setNeedsLayout()
self.invalidateIntrinsicContentSize()
}
Expand Down Expand Up @@ -143,7 +137,7 @@ open class CHIPageControlJalapeno: CHIBasePageControl {
layer.frame = frame
frame.origin.x += self.diameter + self.padding
}
self.active.fillColor = self.tintColor.cgColor
self.active.fillColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
update(for: progress)
}

Expand Down
12 changes: 1 addition & 11 deletions CHIPageControl/CHIPageControlJaloro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ import UIKit

open class CHIPageControlJaloro: CHIBasePageControl {

override open var tintColor: UIColor! {
didSet{
active.backgroundColor = tintColor.cgColor
inactive.forEach() {
$0.backgroundColor = tintColor.withAlphaComponent(0.5).cgColor
}
}
}

@IBInspectable open var elementWidth: CGFloat = 20 {
didSet {
setNeedsLayout()
Expand All @@ -60,7 +51,6 @@ open class CHIPageControlJaloro: CHIBasePageControl {
}

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

active.cornerRadius = self.radius
active.backgroundColor = self.tintColor?.cgColor
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
active.frame = frame

inactive.forEach() { layer in
Expand Down
3 changes: 2 additions & 1 deletion CHIPageControl/CHIPageControlPaprika.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ open class CHIPageControlPaprika: CHIBasePageControl {
}

if let active = elements.first {
active.backgroundColor = self.tintColor.cgColor
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
active.borderWidth = 0
}

min = elements.first?.frame
Expand Down
4 changes: 2 additions & 2 deletions CHIPageControl/CHIPageControlPuya.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ open class CHIPageControlPuya: CHIBasePageControl {
}

override func updateNumberOfPages(_ count: Int) {
elements.forEach() { $0.removeFromSuperlayer() }
elements = [CHILayer]()
elements = (0..<count).map {_ in
let layer = CHILayer()
Expand Down Expand Up @@ -78,7 +77,7 @@ open class CHIPageControlPuya: CHIBasePageControl {
}

if let active = elements.first {
active.backgroundColor = self.tintColor.cgColor
active.backgroundColor = (self.currentPageTintColor ?? self.tintColor)?.cgColor
active.borderWidth = 0
}

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

let index = page + 1
guard elements.indices.contains(index) else { return }
Expand Down
8 changes: 7 additions & 1 deletion CHIPageControl/Core/CHIBasePageControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ import UIKit
setNeedsLayout()
}
}


@IBInspectable open var currentPageTintColor: UIColor? {
didSet {
setNeedsLayout()
}
}

internal var moveToProgress: Double?

private var displayLink: CADisplayLink?
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ target 'Example' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

pod 'CHIPageControl', :git => 'https://github.com/ChiliLabs/CHIPageControl.git'
pod 'CHIPageControl', :path => '../'

end
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ Just add the `CHIPageControl` folder to your project.

use [CocoaPods](https://cocoapods.org) with Podfile:
``` ruby
pod 'CHIPageControl', '~> 0.0.2'
pod 'CHIPageControl', '~> 0.0.3'
```
### Carthage

use [Carthage](https://github.com/Carthage/Carthage) with Cartfile
```ogdl
github "ChiliLabs/CHIPageControl" ~> 0.0.2
github "ChiliLabs/CHIPageControl" ~> 0.0.3
```


Expand All @@ -45,6 +45,7 @@ let pageControl = CHIPageControlAji(frame: CGRect(x: 0, y:0, with: 100, height:
pageControl.numberOfPages = 4
pageControl.radius = 4
pageControl.tintColor = .red
pageControl.currentPageTintColor = .green
pageControl.padding = 6
```
### Updating progress
Expand Down

0 comments on commit 827266f

Please sign in to comment.