Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Commit 011a700

Browse files
Merge pull request #5 from dymx101/master
Add 'setThemeColor' method to footer & header
2 parents 9ac6238 + b300640 commit 011a700

7 files changed

Lines changed: 52 additions & 7 deletions

File tree

PullToRefreshKit/DefaultTableViewController.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ class DefaultTableViewController:UITableViewController{
2424
override func viewDidLoad() {
2525
super.viewDidLoad()
2626
self.tableView.tableFooterView = UIView(frame: CGRect.zero)
27-
_ = self.tableView.setUpHeaderRefresh { [weak self] in
27+
let header = self.tableView.setUpHeaderRefresh { [weak self] in
2828
delay(1.5, closure: {
2929
self?.models = (self?.models.map({_ in random100()}))!
3030
self?.tableView.reloadData()
3131
self?.tableView.endHeaderRefreshing(.success,delay: 0.5)
3232
})
3333
}
34-
_ = self.tableView.setUpFooterRefresh { [weak self] in
34+
header.setThemeColor(themeColor: UIColor.red)
35+
36+
let footer = self.tableView.setUpFooterRefresh { [weak self] in
3537
delay(1.5, closure: {
3638
self?.models.append(random100())
3739
self?.tableView.reloadData()
@@ -42,6 +44,8 @@ class DefaultTableViewController:UITableViewController{
4244
}
4345
})
4446
}
47+
footer.setThemeColor(themeColor: UIColor.red)
48+
4549
self.tableView.beginHeaderRefreshing()
4650
}
4751
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

PullToRefreshKit/MainViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ class MainViewController: UITableViewController {
3535
models.append(section1)
3636
models.append(section2)
3737
models.append(section3)
38-
_ = self.tableView.setUpHeaderRefresh { [weak self] in
38+
let header = self.tableView.setUpHeaderRefresh { [weak self] in
3939
let delayTime = DispatchTime.now() + Double(Int64(2 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
4040
DispatchQueue.main.asyncAfter(deadline: delayTime) {
4141
self?.tableView.endHeaderRefreshing(.success,delay:0.3)
4242
}
4343
}
44+
header.setThemeColor(themeColor: UIColor.blue)
4445
self.tableView.tableFooterView = UIView(frame: CGRect.zero)
4546
}
4647

Source/Classes/Footer.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public enum RefreshMode{
4646
case scrollAndTap
4747
}
4848

49-
open class DefaultRefreshFooter:UIView,RefreshableFooter{
49+
open class DefaultRefreshFooter:UIView, RefreshableFooter, Tintable{
5050
open let spinner:UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: .gray)
5151
open let textLabel:UILabel = UILabel(frame: CGRect(x: 0,y: 0,width: 140,height: 40)).SetUp {
5252
$0.font = UIFont.systemFont(ofSize: 14)
@@ -147,6 +147,12 @@ open class DefaultRefreshFooter:UIView,RefreshableFooter{
147147
}
148148
self.backgroundColor = UIColor.white
149149
}
150+
151+
// MARK: Tintable
152+
func setThemeColor(themeColor: UIColor) {
153+
textLabel.textColor = themeColor
154+
spinner.color = themeColor
155+
}
150156
}
151157

152158
class RefreshFooterContainer:UIView{

Source/Classes/Header.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public enum RefreshKitHeaderText{
3131
case refreshing = 2
3232
case willRefresh = 3
3333
}
34-
open class DefaultRefreshHeader:UIView,RefreshableHeader{
34+
open class DefaultRefreshHeader:UIView,RefreshableHeader, Tintable {
3535
open let spinner:UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: .gray)
3636
open let textLabel:UILabel = UILabel(frame: CGRect(x: 0,y: 0,width: 140,height: 40))
3737
open let imageView:UIImageView = UIImageView(frame: CGRect.zero)
@@ -45,6 +45,7 @@ open class DefaultRefreshHeader:UIView,RefreshableHeader{
4545
let image = UIImage(named: "arrow_down", in: Bundle(for: DefaultRefreshHeader.self), compatibleWith: nil)
4646
imageView.image = image
4747
imageView.sizeToFit()
48+
imageView.becomeTintable()
4849
textLabel.font = UIFont.systemFont(ofSize: 14)
4950
textLabel.textAlignment = .center
5051
self.isHidden = true
@@ -114,18 +115,27 @@ open class DefaultRefreshHeader:UIView,RefreshableHeader{
114115
textLabel.text = textDic[.pullToRefresh]
115116
imageView.image = UIImage(named: "arrow_down", in: Bundle(for: DefaultRefreshHeader.self), compatibleWith: nil)
116117
}
118+
imageView.becomeTintable()
117119
}
118120
open func didCompleteEndRefershingAnimation(_ result:RefreshResult) {
119121
textLabel.text = textDic[.pullToRefresh]
120122
self.isHidden = true
121123
imageView.image = UIImage(named: "arrow_down", in: Bundle(for: DefaultRefreshHeader.self), compatibleWith: nil)
124+
imageView.becomeTintable()
122125
}
123126
open func didBeginRefreshingState() {
124127
self.isHidden = false
125128
textLabel.text = textDic[.refreshing]
126129
spinner.startAnimating()
127130
imageView.isHidden = true
128131
}
132+
133+
// MARK: Tintable
134+
func setThemeColor(themeColor: UIColor) {
135+
imageView.tintColor = themeColor
136+
textLabel.textColor = themeColor
137+
spinner.color = themeColor
138+
}
129139
}
130140

131141
open class RefreshHeaderContainer:UIView{

Source/Classes/Left.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public enum RefreshKitLeftRightText{
1414
case releaseToAction
1515
}
1616

17-
open class DefaultRefreshLeft:UIView,RefreshableLeftRight{
17+
open class DefaultRefreshLeft:UIView, RefreshableLeftRight, Tintable {
1818
open let imageView:UIImageView = UIImageView()
1919
open let textLabel:UILabel = UILabel().SetUp {
2020
$0.font = UIFont.systemFont(ofSize: 14)
@@ -39,6 +39,7 @@ open class DefaultRefreshLeft:UIView,RefreshableLeftRight{
3939
imageView.frame = CGRect(x: 0, y: 0,width: 20, height: 20)
4040
let image = UIImage(named: "arrow_right", in: Bundle(for: DefaultRefreshHeader.self), compatibleWith: nil)
4141
imageView.image = image
42+
imageView.becomeTintable()
4243
textDic[.scrollToAction] = PullToRefreshKitLeftString.scrollToClose
4344
textDic[.releaseToAction] = PullToRefreshKitLeftString.releaseToClose
4445
textLabel.text = textDic[.scrollToAction]
@@ -81,6 +82,12 @@ open class DefaultRefreshLeft:UIView,RefreshableLeftRight{
8182
open func didCompleteEndRefershingAnimation() {
8283
textLabel.text = textDic[.scrollToAction]
8384
}
85+
86+
// MARK: Tintable
87+
func setThemeColor(themeColor: UIColor) {
88+
imageView.tintColor = themeColor
89+
textLabel.textColor = themeColor
90+
}
8491
}
8592

8693
class RefreshLeftContainer:UIView{

Source/Classes/Right.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99
import UIKit
1010

1111

12-
open class DefaultRefreshRight:UIView,RefreshableLeftRight{
12+
open class DefaultRefreshRight:UIView, RefreshableLeftRight, Tintable {
1313
open let imageView:UIImageView = UIImageView()
1414
open let textLabel:UILabel = UILabel().SetUp {
1515
$0.font = UIFont.systemFont(ofSize: 14)
@@ -32,6 +32,7 @@ open class DefaultRefreshRight:UIView,RefreshableLeftRight{
3232
imageView.frame = CGRect(x: 0, y: 0,width: 20, height: 20)
3333
let image = UIImage(named: "arrow_left", in: Bundle(for: DefaultRefreshHeader.self), compatibleWith: nil)
3434
imageView.image = image
35+
imageView.becomeTintable()
3536
textDic[.scrollToAction] = PullToRefreshKitRightString.scrollToViewMore
3637
textDic[.releaseToAction] = PullToRefreshKitRightString.releaseToViewMore
3738
textLabel.text = textDic[.scrollToAction]
@@ -75,6 +76,12 @@ open class DefaultRefreshRight:UIView,RefreshableLeftRight{
7576
open func didBeginRefreshing() {
7677

7778
}
79+
80+
// MARK: Tintable
81+
func setThemeColor(themeColor: UIColor) {
82+
imageView.tintColor = themeColor
83+
textLabel.textColor = themeColor
84+
}
7885
}
7986

8087
class RefreshRightContainer:UIView{

Source/Classes/Utils.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,13 @@ struct PullToRefreshKitRightString{
5656
static let releaseToViewMore = "滑动浏览更多"
5757
}
5858

59+
protocol Tintable {
60+
func setThemeColor(themeColor: UIColor)
61+
}
62+
63+
extension UIImageView {
64+
func becomeTintable() {
65+
image = image?.withRenderingMode(.alwaysTemplate)
66+
}
67+
}
68+

0 commit comments

Comments
 (0)