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

Commit e9705e4

Browse files
Add banner example,add custom header footer example
1 parent b66bc88 commit e9705e4

17 files changed

Lines changed: 338 additions & 74 deletions

PullToRefreshKit.xcodeproj/project.pbxproj

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
52261F0B1D36730F00161ADF /* DefaultCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52261F0A1D36730F00161ADF /* DefaultCollectionViewController.swift */; };
11+
52261F0D1D36832600161ADF /* ConfigDefaultHeaderFooterController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52261F0C1D36832600161ADF /* ConfigDefaultHeaderFooterController.swift */; };
12+
52261F101D36878A00161ADF /* banner1.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 52261F0E1D36878A00161ADF /* banner1.jpg */; };
13+
52261F111D36878A00161ADF /* banner2.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 52261F0F1D36878A00161ADF /* banner2.jpg */; };
14+
52261F131D36879C00161ADF /* DefaultBannerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52261F121D36879C00161ADF /* DefaultBannerController.swift */; };
1015
52BB29171D3639500091F36B /* arrow_down@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 52BB290E1D3639500091F36B /* arrow_down@3x.png */; };
1116
52BB29181D3639500091F36B /* arrow_left@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 52BB290F1D3639500091F36B /* arrow_left@3x.png */; };
1217
52BB29191D3639500091F36B /* arrow_right@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 52BB29101D3639500091F36B /* arrow_right@3x.png */; };
@@ -19,7 +24,9 @@
1924
52BB29231D3640610091F36B /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 52BB29201D3640610091F36B /* LICENSE */; };
2025
52BB29241D3640610091F36B /* PullToRefreshKit.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 52BB29211D3640610091F36B /* PullToRefreshKit.podspec */; };
2126
52BB29281D3644D00091F36B /* SectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52BB29271D3644D00091F36B /* SectionModel.swift */; };
22-
52C7DD961D3532F8009A9C8C /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C7DD951D3532F8009A9C8C /* SecondViewController.swift */; };
27+
52BB292E1D364C6D0091F36B /* RowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52BB292D1D364C6D0091F36B /* RowModel.swift */; };
28+
52BB29321D364E490091F36B /* DefaultTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52BB29311D364E490091F36B /* DefaultTableViewController.swift */; };
29+
52BB29341D3655B90091F36B /* Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52BB29331D3655B90091F36B /* Util.swift */; };
2330
52E8FB401D336E26000D0BF1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52E8FB3F1D336E26000D0BF1 /* AppDelegate.swift */; };
2431
52E8FB421D336E26000D0BF1 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52E8FB411D336E26000D0BF1 /* MainViewController.swift */; };
2532
52E8FB451D336E26000D0BF1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 52E8FB431D336E26000D0BF1 /* Main.storyboard */; };
@@ -28,6 +35,11 @@
2835
/* End PBXBuildFile section */
2936

3037
/* Begin PBXFileReference section */
38+
52261F0A1D36730F00161ADF /* DefaultCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultCollectionViewController.swift; sourceTree = "<group>"; };
39+
52261F0C1D36832600161ADF /* ConfigDefaultHeaderFooterController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigDefaultHeaderFooterController.swift; sourceTree = "<group>"; };
40+
52261F0E1D36878A00161ADF /* banner1.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = banner1.jpg; sourceTree = "<group>"; };
41+
52261F0F1D36878A00161ADF /* banner2.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = banner2.jpg; sourceTree = "<group>"; };
42+
52261F121D36879C00161ADF /* DefaultBannerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultBannerController.swift; sourceTree = "<group>"; };
3143
52BB290E1D3639500091F36B /* arrow_down@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "arrow_down@3x.png"; sourceTree = "<group>"; };
3244
52BB290F1D3639500091F36B /* arrow_left@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "arrow_left@3x.png"; sourceTree = "<group>"; };
3345
52BB29101D3639500091F36B /* arrow_right@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "arrow_right@3x.png"; sourceTree = "<group>"; };
@@ -41,7 +53,9 @@
4153
52BB29211D3640610091F36B /* PullToRefreshKit.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PullToRefreshKit.podspec; sourceTree = "<group>"; };
4254
52BB29221D3640610091F36B /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
4355
52BB29271D3644D00091F36B /* SectionModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SectionModel.swift; sourceTree = "<group>"; };
44-
52C7DD951D3532F8009A9C8C /* SecondViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecondViewController.swift; sourceTree = "<group>"; };
56+
52BB292D1D364C6D0091F36B /* RowModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowModel.swift; sourceTree = "<group>"; };
57+
52BB29311D364E490091F36B /* DefaultTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultTableViewController.swift; sourceTree = "<group>"; };
58+
52BB29331D3655B90091F36B /* Util.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Util.swift; sourceTree = "<group>"; };
4559
52E8FB3C1D336E26000D0BF1 /* PullToRefreshKit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PullToRefreshKit.app; sourceTree = BUILT_PRODUCTS_DIR; };
4660
52E8FB3F1D336E26000D0BF1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
4761
52E8FB411D336E26000D0BF1 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
@@ -65,13 +79,57 @@
6579
52BB29261D3640700091F36B /* Examples */ = {
6680
isa = PBXGroup;
6781
children = (
68-
52E8FB411D336E26000D0BF1 /* MainViewController.swift */,
69-
52C7DD951D3532F8009A9C8C /* SecondViewController.swift */,
82+
52BB292D1D364C6D0091F36B /* RowModel.swift */,
7083
52BB29271D3644D00091F36B /* SectionModel.swift */,
84+
52E8FB411D336E26000D0BF1 /* MainViewController.swift */,
85+
52BB29331D3655B90091F36B /* Util.swift */,
86+
52BB292B1D364C350091F36B /* Default */,
87+
52BB292C1D364C390091F36B /* Custom */,
7188
);
7289
name = Examples;
7390
sourceTree = "<group>";
7491
};
92+
52BB29291D364C1C0091F36B /* Images */ = {
93+
isa = PBXGroup;
94+
children = (
95+
52BB290E1D3639500091F36B /* arrow_down@3x.png */,
96+
52BB290F1D3639500091F36B /* arrow_left@3x.png */,
97+
52BB29101D3639500091F36B /* arrow_right@3x.png */,
98+
);
99+
name = Images;
100+
sourceTree = "<group>";
101+
};
102+
52BB292A1D364C260091F36B /* Classes */ = {
103+
isa = PBXGroup;
104+
children = (
105+
52BB29111D3639500091F36B /* Const.swift */,
106+
52BB29121D3639500091F36B /* Footer.swift */,
107+
52BB29131D3639500091F36B /* Header.swift */,
108+
52BB29141D3639500091F36B /* Left.swift */,
109+
52BB29151D3639500091F36B /* PullToRefreshKit.swift */,
110+
52BB29161D3639500091F36B /* Right.swift */,
111+
);
112+
name = Classes;
113+
sourceTree = "<group>";
114+
};
115+
52BB292B1D364C350091F36B /* Default */ = {
116+
isa = PBXGroup;
117+
children = (
118+
52BB29311D364E490091F36B /* DefaultTableViewController.swift */,
119+
52261F0A1D36730F00161ADF /* DefaultCollectionViewController.swift */,
120+
52261F0C1D36832600161ADF /* ConfigDefaultHeaderFooterController.swift */,
121+
52261F121D36879C00161ADF /* DefaultBannerController.swift */,
122+
);
123+
name = Default;
124+
sourceTree = "<group>";
125+
};
126+
52BB292C1D364C390091F36B /* Custom */ = {
127+
isa = PBXGroup;
128+
children = (
129+
);
130+
name = Custom;
131+
sourceTree = "<group>";
132+
};
75133
52E8FB331D336E26000D0BF1 = {
76134
isa = PBXGroup;
77135
children = (
@@ -99,6 +157,8 @@
99157
52E8FB3F1D336E26000D0BF1 /* AppDelegate.swift */,
100158
52E8FB431D336E26000D0BF1 /* Main.storyboard */,
101159
52E8FB461D336E26000D0BF1 /* Assets.xcassets */,
160+
52261F0E1D36878A00161ADF /* banner1.jpg */,
161+
52261F0F1D36878A00161ADF /* banner2.jpg */,
102162
52E8FB481D336E26000D0BF1 /* LaunchScreen.storyboard */,
103163
52E8FB4B1D336E26000D0BF1 /* Info.plist */,
104164
);
@@ -108,15 +168,8 @@
108168
52E8FB511D336FCE000D0BF1 /* Sources */ = {
109169
isa = PBXGroup;
110170
children = (
111-
52BB290E1D3639500091F36B /* arrow_down@3x.png */,
112-
52BB290F1D3639500091F36B /* arrow_left@3x.png */,
113-
52BB29101D3639500091F36B /* arrow_right@3x.png */,
114-
52BB29111D3639500091F36B /* Const.swift */,
115-
52BB29121D3639500091F36B /* Footer.swift */,
116-
52BB29131D3639500091F36B /* Header.swift */,
117-
52BB29141D3639500091F36B /* Left.swift */,
118-
52BB29151D3639500091F36B /* PullToRefreshKit.swift */,
119-
52BB29161D3639500091F36B /* Right.swift */,
171+
52BB292A1D364C260091F36B /* Classes */,
172+
52BB29291D364C1C0091F36B /* Images */,
120173
);
121174
name = Sources;
122175
sourceTree = "<group>";
@@ -179,7 +232,9 @@
179232
isa = PBXResourcesBuildPhase;
180233
buildActionMask = 2147483647;
181234
files = (
235+
52261F111D36878A00161ADF /* banner2.jpg in Resources */,
182236
52BB29191D3639500091F36B /* arrow_right@3x.png in Resources */,
237+
52261F101D36878A00161ADF /* banner1.jpg in Resources */,
183238
52E8FB4A1D336E26000D0BF1 /* LaunchScreen.storyboard in Resources */,
184239
52BB29171D3639500091F36B /* arrow_down@3x.png in Resources */,
185240
52BB29241D3640610091F36B /* PullToRefreshKit.podspec in Resources */,
@@ -198,14 +253,19 @@
198253
buildActionMask = 2147483647;
199254
files = (
200255
52BB291E1D3639500091F36B /* PullToRefreshKit.swift in Sources */,
201-
52C7DD961D3532F8009A9C8C /* SecondViewController.swift in Sources */,
202256
52BB291D1D3639500091F36B /* Left.swift in Sources */,
203257
52BB29281D3644D00091F36B /* SectionModel.swift in Sources */,
204258
52BB291F1D3639500091F36B /* Right.swift in Sources */,
205259
52BB291A1D3639500091F36B /* Const.swift in Sources */,
260+
52261F131D36879C00161ADF /* DefaultBannerController.swift in Sources */,
206261
52E8FB421D336E26000D0BF1 /* MainViewController.swift in Sources */,
207262
52E8FB401D336E26000D0BF1 /* AppDelegate.swift in Sources */,
263+
52BB29341D3655B90091F36B /* Util.swift in Sources */,
264+
52261F0B1D36730F00161ADF /* DefaultCollectionViewController.swift in Sources */,
265+
52261F0D1D36832600161ADF /* ConfigDefaultHeaderFooterController.swift in Sources */,
208266
52BB291C1D3639500091F36B /* Header.swift in Sources */,
267+
52BB29321D364E490091F36B /* DefaultTableViewController.swift in Sources */,
268+
52BB292E1D364C6D0091F36B /* RowModel.swift in Sources */,
209269
52BB291B1D3639500091F36B /* Footer.swift in Sources */,
210270
);
211271
runOnlyForDeploymentPostprocessing = 0;

PullToRefreshKit/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
"idiom" : "ipad",
6060
"size" : "76x76",
6161
"scale" : "2x"
62+
},
63+
{
64+
"idiom" : "ipad",
65+
"size" : "83.5x83.5",
66+
"scale" : "2x"
6267
}
6368
],
6469
"info" : {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// ConfigDefaultHeaderFooterController.swift
3+
// PullToRefreshKit
4+
//
5+
// Created by huangwenchen on 16/7/13.
6+
// Copyright © 2016年 Leo. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class ConfigDefaultHeaderFooterController: UITableViewController {
12+
var models = [1,2,3,4,5,6,7,8,9,10]
13+
14+
override func viewDidLoad() {
15+
super.viewDidLoad()
16+
self.tableView.tableFooterView = UIView(frame: CGRectZero)
17+
18+
//Header
19+
self.tableView.setUpHeaderRefresh { [weak self] in
20+
delay(1.5, closure: {
21+
self?.models = (self?.models.map({_ in random100()}))!
22+
self?.tableView.reloadData()
23+
self?.tableView.endHeaderRefreshing(.Success)
24+
})
25+
}.SetUp { (header) in
26+
header.setText("Pull to refresh", mode: .pullToRefresh)
27+
header.setText("Release to refresh", mode: .releaseToRefresh)
28+
header.setText("Refresh successfully", mode: .refreshSuccess)
29+
header.setText("Refreshing...", mode: .refreshing)
30+
header.setText("Refresh failed", mode: .refreshFailure)
31+
header.setText("Refresh error", mode: .refreshError)
32+
header.textLabel.textColor = UIColor.orangeColor()
33+
header.imageView.image = nil
34+
}
35+
//Footer
36+
37+
self.tableView.setUpFooterRefresh { [weak self] in
38+
delay(1.5, closure: {
39+
self?.models.append(random100())
40+
self?.tableView.reloadData()
41+
self?.tableView.endFooterRefreshing()
42+
})
43+
}.SetUp { (footer) in
44+
45+
}
46+
}
47+
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
48+
return models.count
49+
}
50+
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
51+
return 44.0
52+
}
53+
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
54+
var cell = tableView.dequeueReusableCellWithIdentifier("cell")
55+
if cell == nil {
56+
cell = UITableViewCell(style: .Default, reuseIdentifier: "cell")
57+
}
58+
cell?.textLabel?.text = "\(models[indexPath.row])"
59+
return cell!
60+
}
61+
deinit{
62+
print("Deinit of DefaultTableViewController")
63+
}
64+
65+
}

PullToRefreshKit/Const.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct PullToRefreshKitConst{
3030
}
3131

3232
struct PullToRefreshKitHeaderString{
33-
static let downToRefersh = "下拉可以刷新"
33+
static let pullToRefresh = "下拉可以刷新"
3434
static let releaseToRefresh = "松开立即刷新"
3535
static let refreshSuccess = "刷新成功"
3636
static let refreshError = "刷新出错"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// DefaultBannerController.swift
3+
// PullToRefreshKit
4+
//
5+
// Created by huangwenchen on 16/7/13.
6+
// Copyright © 2016年 Leo. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
class DefaultBannerController: UIViewController {
12+
let scrollView = UIScrollView()
13+
override func viewDidLoad() {
14+
super.viewDidLoad()
15+
self.navigationItem.title = "Banners"
16+
self.automaticallyAdjustsScrollViewInsets = false
17+
setUpViews()
18+
scrollView.setUpLeftRefresh { [weak self] in
19+
self?.navigationController?.popViewControllerAnimated(true)
20+
}
21+
scrollView.setUpRightRefresh { [weak self] in
22+
let nvc = DefaultBannerController()
23+
self?.navigationController?.pushViewController(nvc, animated: true)
24+
}
25+
}
26+
27+
func setUpViews(){
28+
view.backgroundColor = UIColor.whiteColor()
29+
let screenWidth = UIScreen.mainScreen().bounds.size.width;
30+
let scrollheight = screenWidth / 8.0 * 5.0
31+
scrollView.frame = CGRectMake(0, 0, screenWidth, scrollheight)
32+
scrollView.center = self.view.center
33+
self.view.addSubview(scrollView)
34+
let imageView1 = UIImageView(frame:CGRectMake(0, 0, screenWidth, scrollheight))
35+
imageView1.image = UIImage(named: "banner1.jpg")
36+
scrollView.addSubview(imageView1)
37+
38+
let imageView2 = UIImageView(frame:CGRectMake(screenWidth, 0, screenWidth, scrollheight))
39+
imageView2.image = UIImage(named: "banner2.jpg")
40+
scrollView.addSubview(imageView2)
41+
42+
scrollView.pagingEnabled = true
43+
scrollView.contentSize = CGSizeMake(screenWidth * 2, scrollheight)
44+
}
45+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// DefaultCollectionViewController.swift
3+
// PullToRefreshKit
4+
//
5+
// Created by huangwenchen on 16/7/13.
6+
// Copyright © 2016年 Leo. All rights reserved.
7+
//
8+
9+
import Foundation
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// WebviewController.swift
3+
// PullToRefreshKit
4+
//
5+
// Created by huangwenchen on 16/7/13.
6+
// Copyright © 2016年 Leo. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
class DefaultTableViewController:UITableViewController{
12+
var models = [1,2,3,4,5,6,7,8,9,10]
13+
14+
override func viewDidLoad() {
15+
super.viewDidLoad()
16+
self.tableView.tableFooterView = UIView(frame: CGRectZero)
17+
self.tableView.setUpHeaderRefresh { [weak self] in
18+
delay(1.5, closure: {
19+
self?.models = (self?.models.map({_ in random100()}))!
20+
self?.tableView.reloadData()
21+
self?.tableView.endHeaderRefreshing(.Success)
22+
})
23+
}
24+
self.tableView.setUpFooterRefresh { [weak self] in
25+
delay(1.5, closure: {
26+
self?.models.append(random100())
27+
self?.tableView.reloadData()
28+
self?.tableView.endFooterRefreshing()
29+
})
30+
}
31+
}
32+
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
33+
return models.count
34+
}
35+
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
36+
return 44.0
37+
}
38+
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
39+
var cell = tableView.dequeueReusableCellWithIdentifier("cell")
40+
if cell == nil {
41+
cell = UITableViewCell(style: .Default, reuseIdentifier: "cell")
42+
}
43+
cell?.textLabel?.text = "\(models[indexPath.row])"
44+
return cell!
45+
}
46+
deinit{
47+
print("Deinit of DefaultTableViewController")
48+
}
49+
}

0 commit comments

Comments
 (0)