Skip to content

Commit 78ce3be

Browse files
authored
Merge pull request #1 from hoangtaiki/develop
Release version 1.0.0
2 parents 714b263 + 8d9cd35 commit 78ce3be

23 files changed

+1299
-54
lines changed

.swift-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "ic_nav_back.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"filename" : "ic_nav_back@2x.png",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"filename" : "ic_nav_back@3x.png",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"version" : 1,
21+
"author" : "xcode"
22+
}
23+
}
223 Bytes
Loading
396 Bytes
Loading
601 Bytes
Loading
Lines changed: 106 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,118 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" systemVersion="17A277" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="76W-wj-HtM">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
5-
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
69
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
710
</dependencies>
811
<scenes>
9-
<!--View Controller-->
10-
<scene sceneID="tne-QT-ifu">
12+
<!--List View Controller-->
13+
<scene sceneID="MHX-c9-hBw">
1114
<objects>
12-
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
13-
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
15+
<tableViewController id="uEA-F2-W1f" customClass="ListViewController" customModule="iOS_Example" customModuleProvider="target" sceneMemberID="viewController">
16+
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="ziD-DB-rgL">
1417
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1518
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
16-
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
17-
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
18-
</view>
19-
</viewController>
20-
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
19+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
20+
<sections>
21+
<tableViewSection id="Pwl-se-PRi">
22+
<cells>
23+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" rowHeight="65" id="j81-MR-zVJ">
24+
<rect key="frame" x="0.0" y="0.0" width="375" height="65"/>
25+
<autoresizingMask key="autoresizingMask"/>
26+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="j81-MR-zVJ" id="Xqk-sW-cNg">
27+
<rect key="frame" x="0.0" y="0.0" width="375" height="65"/>
28+
<autoresizingMask key="autoresizingMask"/>
29+
<subviews>
30+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Default Header" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gWC-sT-lRi">
31+
<rect key="frame" x="16" y="22" width="343" height="21"/>
32+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
33+
<nil key="textColor"/>
34+
<nil key="highlightedColor"/>
35+
</label>
36+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="TvY-tZ-md7">
37+
<rect key="frame" x="16" y="64" width="359" height="1"/>
38+
<color key="backgroundColor" red="0.92143100499999997" green="0.92145264149999995" blue="0.92144101860000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
39+
<constraints>
40+
<constraint firstAttribute="height" constant="1" id="qgc-Ur-t7I"/>
41+
</constraints>
42+
</view>
43+
</subviews>
44+
<constraints>
45+
<constraint firstItem="gWC-sT-lRi" firstAttribute="centerY" secondItem="Xqk-sW-cNg" secondAttribute="centerY" id="0uN-b9-VzG"/>
46+
<constraint firstItem="gWC-sT-lRi" firstAttribute="leading" secondItem="Xqk-sW-cNg" secondAttribute="leading" constant="16" id="5tS-7I-bMl"/>
47+
<constraint firstAttribute="trailing" secondItem="gWC-sT-lRi" secondAttribute="trailing" constant="16" id="Cp2-Lu-dZ0"/>
48+
<constraint firstAttribute="bottom" secondItem="TvY-tZ-md7" secondAttribute="bottom" id="HJM-Gy-wnc"/>
49+
<constraint firstItem="TvY-tZ-md7" firstAttribute="leading" secondItem="Xqk-sW-cNg" secondAttribute="leading" constant="16" id="Lpk-JS-rir"/>
50+
<constraint firstAttribute="trailing" secondItem="TvY-tZ-md7" secondAttribute="trailing" id="iRx-8i-ujn"/>
51+
</constraints>
52+
</tableViewCellContentView>
53+
</tableViewCell>
54+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" rowHeight="65" id="yyI-Da-Vim">
55+
<rect key="frame" x="0.0" y="65" width="375" height="65"/>
56+
<autoresizingMask key="autoresizingMask"/>
57+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="yyI-Da-Vim" id="lCd-h2-IZk">
58+
<rect key="frame" x="0.0" y="0.0" width="375" height="65"/>
59+
<autoresizingMask key="autoresizingMask"/>
60+
<subviews>
61+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Custom Header" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YHG-Ij-1vp">
62+
<rect key="frame" x="16" y="22" width="343" height="21"/>
63+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
64+
<nil key="textColor"/>
65+
<nil key="highlightedColor"/>
66+
</label>
67+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5bJ-Uy-RNN">
68+
<rect key="frame" x="16" y="64" width="359" height="1"/>
69+
<color key="backgroundColor" red="0.92143100499999997" green="0.92145264149999995" blue="0.92144101860000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
70+
<constraints>
71+
<constraint firstAttribute="height" constant="1" id="Pya-dy-eny"/>
72+
</constraints>
73+
</view>
74+
</subviews>
75+
<constraints>
76+
<constraint firstItem="YHG-Ij-1vp" firstAttribute="centerY" secondItem="lCd-h2-IZk" secondAttribute="centerY" id="3H3-z6-GWB"/>
77+
<constraint firstItem="YHG-Ij-1vp" firstAttribute="leading" secondItem="lCd-h2-IZk" secondAttribute="leading" constant="16" id="MGm-xe-2ax"/>
78+
<constraint firstItem="5bJ-Uy-RNN" firstAttribute="leading" secondItem="lCd-h2-IZk" secondAttribute="leading" constant="16" id="WPd-Kl-lSw"/>
79+
<constraint firstAttribute="trailing" secondItem="5bJ-Uy-RNN" secondAttribute="trailing" id="dwh-6u-twr"/>
80+
<constraint firstAttribute="bottom" secondItem="5bJ-Uy-RNN" secondAttribute="bottom" id="oaq-1D-9Fi"/>
81+
<constraint firstAttribute="trailing" secondItem="YHG-Ij-1vp" secondAttribute="trailing" constant="16" id="uUm-gL-y3a"/>
82+
</constraints>
83+
</tableViewCellContentView>
84+
</tableViewCell>
85+
</cells>
86+
</tableViewSection>
87+
</sections>
88+
<connections>
89+
<outlet property="dataSource" destination="uEA-F2-W1f" id="H0o-Og-Zaa"/>
90+
<outlet property="delegate" destination="uEA-F2-W1f" id="ckB-M5-CbK"/>
91+
</connections>
92+
</tableView>
93+
<navigationItem key="navigationItem" id="3dA-pg-doV"/>
94+
</tableViewController>
95+
<placeholder placeholderIdentifier="IBFirstResponder" id="PY5-dP-3tJ" userLabel="First Responder" sceneMemberID="firstResponder"/>
2196
</objects>
97+
<point key="canvasLocation" x="3703.1999999999998" y="-319.79010494752629"/>
98+
</scene>
99+
<!--Navigation Controller-->
100+
<scene sceneID="b7A-on-P9V">
101+
<objects>
102+
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="76W-wj-HtM" sceneMemberID="viewController">
103+
<toolbarItems/>
104+
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Oz2-ua-MGd">
105+
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
106+
<autoresizingMask key="autoresizingMask"/>
107+
</navigationBar>
108+
<nil name="viewControllers"/>
109+
<connections>
110+
<segue destination="uEA-F2-W1f" kind="relationship" relationship="rootViewController" id="sgj-aN-2wk"/>
111+
</connections>
112+
</navigationController>
113+
<placeholder placeholderIdentifier="IBFirstResponder" id="Nr9-66-JXG" userLabel="First Responder" sceneMemberID="firstResponder"/>
114+
</objects>
115+
<point key="canvasLocation" x="2764" y="-319.79010494752629"/>
22116
</scene>
23117
</scenes>
24118
</document>

Example/Source/AppDelegate.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1616

1717
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
19+
20+
let appearance = UINavigationBar.appearance()
21+
appearance.barStyle = .black
22+
appearance.isTranslucent = false
23+
appearance.tintColor = .white
24+
appearance.barTintColor = UIColor(red: 82/255, green: 100/255, blue: 176/255, alpha: 0.96)
25+
appearance.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white,
26+
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.medium) ]
27+
1928
return true
2029
}
2130

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// ListViewController.swift
3+
// iOS Example
4+
//
5+
// Created by Hoangtaiki on 7/29/18.
6+
// Copyright © 2018 toprating. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class ListViewController: UITableViewController {
12+
13+
override func viewDidLoad() {
14+
super.viewDidLoad()
15+
16+
title = "List Header Style"
17+
}
18+
19+
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
20+
guard let headerStyle = HeaderStyle(at: indexPath) else { return }
21+
22+
let refreshViewController = RefreshViewController(headerStyle: headerStyle)
23+
navigationController?.pushViewController(refreshViewController, animated: true)
24+
}
25+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
//
2+
// ViewController.swift
3+
// iOS Example
4+
//
5+
// Created by Hoangtaiki on 7/20/18.
6+
// Copyright © 2018 toprating. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import Refreshable
11+
12+
enum HeaderStyle: Int {
13+
case `default` = 0
14+
case custom
15+
16+
init?(at indexPath: IndexPath) {
17+
self.init(rawValue: indexPath.row)
18+
}
19+
}
20+
21+
class RefreshViewController: UITableViewController {
22+
23+
var numberRows = 10
24+
var headerStyle: HeaderStyle = .default
25+
26+
init(headerStyle: HeaderStyle) {
27+
self.headerStyle = headerStyle
28+
super.init(nibName: nil, bundle: nil)
29+
}
30+
31+
required init?(coder aDecoder: NSCoder) {
32+
fatalError("init(coder:) has not been implemented")
33+
}
34+
35+
override func viewDidLoad() {
36+
super.viewDidLoad()
37+
38+
title = "Refreshable"
39+
addBackBarButton()
40+
view.backgroundColor = UIColor(red: 210/255, green: 210/255, blue: 210/255, alpha: 1)
41+
42+
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
43+
tableView.register(SampleCell.nib(), forCellReuseIdentifier: SampleCell.reuseIdentifier)
44+
45+
// Set up pull to refresh
46+
setUpPullToRefresh()
47+
48+
tableView.addLoadMore(action: { [weak self] in
49+
self?.handleLoadMore()
50+
})
51+
}
52+
53+
override func numberOfSections(in tableView: UITableView) -> Int {
54+
return 1
55+
}
56+
57+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
58+
return numberRows
59+
}
60+
61+
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
62+
return 128
63+
}
64+
65+
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
66+
let cell = tableView.dequeueReusableCell(withIdentifier: SampleCell.reuseIdentifier, for: indexPath) as! SampleCell
67+
cell.isSeperationLineHidden = indexPath.row == numberRows - 1
68+
cell.indexNumberLabel.text = indexPath.row.description
69+
70+
return cell
71+
}
72+
}
73+
74+
extension RefreshViewController {
75+
76+
77+
private func setUpPullToRefresh() {
78+
switch headerStyle {
79+
case .custom:
80+
let animator = TextLoadingAnimator()
81+
tableView.addPullToRefresh(withAnimator: animator, height: 60) { [weak self] in
82+
self?.handleRefresh()
83+
}
84+
85+
case .default:
86+
tableView.addPullToRefresh(action: { [weak self] in
87+
self?.handleRefresh()
88+
})
89+
90+
}
91+
}
92+
93+
// Reset numberOfRows to original value
94+
// Reload data and enable load more
95+
private func handleRefresh() {
96+
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
97+
self.numberRows = 10
98+
self.tableView.reloadData()
99+
self.tableView.stopPullToRefresh()
100+
self.tableView.setLoadMoreEnable(true)
101+
}
102+
}
103+
104+
private func updateLoadMoreEnable() {
105+
if numberRows < 16 { return }
106+
107+
tableView.setLoadMoreEnable(false)
108+
}
109+
110+
private func handleLoadMore() {
111+
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
112+
self.tableView.beginUpdates()
113+
self.numberRows += 3
114+
self.tableView.insertRows(at: [IndexPath(row: self.numberRows - 3, section: 0),
115+
IndexPath(row: self.numberRows - 2, section: 0),
116+
IndexPath(row: self.numberRows - 1, section: 0)],
117+
with: .automatic)
118+
self.tableView.endUpdates()
119+
self.tableView.stopLoadMore()
120+
121+
// Check data to enable/disable load more
122+
self.updateLoadMoreEnable()
123+
}
124+
}
125+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// UIViewController.swift
3+
// iOS Example
4+
//
5+
// Created by Hoangtaiki on 7/29/18.
6+
// Copyright © 2018 toprating. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension UIViewController {
12+
13+
public func addBackBarButton() {
14+
let image = UIImage(named: "ic_nav_back")
15+
let button = UIBarButtonItem(image: image,
16+
style: .plain,
17+
target: self,
18+
action: #selector(tappedOnBackBarButton(sender:)))
19+
navigationItem.leftBarButtonItem = button
20+
}
21+
22+
@objc open func tappedOnBackBarButton(sender: UIBarButtonItem) {
23+
_ = navigationController?.popViewController(animated: true)
24+
}
25+
}

0 commit comments

Comments
 (0)