Skip to content

Commit b3271e2

Browse files
committed
Add sample code
1 parent 9990181 commit b3271e2

File tree

4 files changed

+103
-11
lines changed

4 files changed

+103
-11
lines changed

Example/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ EXTERNAL SOURCES:
1515
:path: "../"
1616

1717
SPEC CHECKSUMS:
18-
ReusableScrollMenuView: 06598b3c82a337cc799d0ec2afb1fd71a402ea90
18+
ReusableScrollMenuView: 73c7065424ee0360d5eb20e5b1ba8800a74c2b2b
1919
SnapKit: fe8a619752f3f27075cc9a90244d75c6c3f27e2a
2020

2121
PODFILE CHECKSUM: 8ccf3b2ab0c0efc87aedad13ce51c9ff65d8e003

Example/ReusableScrollMenuView.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@
488488
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
489489
DEVELOPMENT_TEAM = 6VQ654HEG7;
490490
INFOPLIST_FILE = ReusableScrollMenuView/Info.plist;
491-
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
491+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
492492
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
493493
MODULE_NAME = ExampleApp;
494494
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
@@ -505,7 +505,7 @@
505505
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
506506
DEVELOPMENT_TEAM = 6VQ654HEG7;
507507
INFOPLIST_FILE = ReusableScrollMenuView/Info.plist;
508-
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
508+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
509509
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
510510
MODULE_NAME = ExampleApp;
511511
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3-
<device id="retina4_7" orientation="portrait">
4-
<adaptation id="fullscreen"/>
5-
</device>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="I00-Cg-n5V">
3+
<device id="retina4_7" orientation="portrait" appearance="light"/>
64
<dependencies>
75
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
97
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
108
</dependencies>
119
<scenes>
12-
<!--View Controller-->
10+
<!--Navigation Controller-->
11+
<scene sceneID="NGO-qy-PSC">
12+
<objects>
13+
<navigationController id="I00-Cg-n5V" sceneMemberID="viewController">
14+
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" largeTitles="YES" id="7g3-Gv-kWt">
15+
<rect key="frame" x="0.0" y="0.0" width="375" height="96"/>
16+
<autoresizingMask key="autoresizingMask"/>
17+
</navigationBar>
18+
<connections>
19+
<segue destination="vXZ-lx-hvc" kind="relationship" relationship="rootViewController" id="41h-YM-P1s"/>
20+
</connections>
21+
</navigationController>
22+
<placeholder placeholderIdentifier="IBFirstResponder" id="ptI-ri-dD3" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
23+
</objects>
24+
<point key="canvasLocation" x="66" y="125"/>
25+
</scene>
26+
<!--Hello-->
1327
<scene sceneID="ufC-wZ-h7g">
1428
<objects>
1529
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="ReusableScrollMenuView_Example" customModuleProvider="target" sceneMemberID="viewController">
@@ -22,9 +36,11 @@
2236
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2337
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2438
</view>
39+
<navigationItem key="navigationItem" title="Hello" id="SvP-7T-aSp"/>
2540
</viewController>
2641
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
2742
</objects>
43+
<point key="canvasLocation" x="849" y="125"/>
2844
</scene>
2945
</scenes>
3046
</document>

Example/ReusableScrollMenuView/ViewController.swift

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,94 @@
77
//
88

99
import UIKit
10+
import ReusableScrollMenuView
1011

1112
class ViewController: UIViewController {
1213

14+
lazy var tableView: UITableView = {
15+
let tableView = UITableView(frame: .zero, style: .plain)
16+
tableView.delegate = self
17+
tableView.dataSource = self
18+
tableView.separatorStyle = .none
19+
tableView.estimatedSectionHeaderHeight = 50
20+
tableView.scrollIndicatorInsets = UIEdgeInsets(top: 50, left: 0, bottom: 0, right: 0)
21+
return tableView
22+
}()
23+
24+
let menuTitles = ["Company", "Position", "Career", "Lifestyle", "Topic", "Longcat is very long"]
25+
var currentMenuIndex = 0
26+
1327
override func viewDidLoad() {
1428
super.viewDidLoad()
15-
// Do any additional setup after loading the view, typically from a nib.
29+
30+
addTableView()
1631
}
1732

1833
override func didReceiveMemoryWarning() {
1934
super.didReceiveMemoryWarning()
20-
// Dispose of any resources that can be recreated.
35+
}
36+
37+
func addTableView() {
38+
self.view.addSubview(tableView)
39+
40+
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "numberCell")
41+
tableView.register(ReusableScrollMenuView.self, forHeaderFooterViewReuseIdentifier: ReusableScrollMenuView.reuseIdentifier)
42+
43+
tableView.snp.makeConstraints { (maker) in
44+
maker.edges.equalToSuperview()
45+
}
2146
}
2247

2348
}
2449

50+
extension ViewController: UITableViewDelegate, UITableViewDataSource {
51+
func numberOfSections(in tableView: UITableView) -> Int {
52+
return 1
53+
}
54+
55+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
56+
return 100
57+
}
58+
59+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
60+
let cell = tableView.dequeueReusableCell(withIdentifier: "numberCell", for: indexPath)
61+
cell.textLabel?.text = "\(indexPath.row)"
62+
return cell
63+
}
64+
65+
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
66+
guard let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: ReusableScrollMenuView.reuseIdentifier) as? ReusableScrollMenuView else { return nil }
67+
view.bgColor = .systemBackground
68+
view.highlightColor = .systemOrange
69+
view.delegate = self
70+
view.dataSource = self
71+
return view
72+
}
73+
74+
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
75+
return UITableViewAutomaticDimension
76+
}
77+
78+
func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
79+
return 50
80+
}
81+
}
82+
83+
extension ViewController: ReusableScrollMenuViewDelegate {
84+
func headerMenuView(_ headerMenuView: ReusableScrollMenuView, didSelectMenu index: Int) {
85+
guard menuTitles.count > index else { return }
86+
self.currentMenuIndex = index
87+
88+
print("Menu \(index): \(menuTitles[index])")
89+
}
90+
}
91+
92+
extension ViewController: ReusableScrollMenuViewDataSource {
93+
func titlesForMenuView(_ menuView: ReusableScrollMenuView) -> [String] {
94+
return menuTitles
95+
}
96+
97+
func selectedIndexForMenuView(_ menuView: ReusableScrollMenuView) -> Int? {
98+
return currentMenuIndex
99+
}
100+
}

0 commit comments

Comments
 (0)