Skip to content
This repository was archived by the owner on Jun 17, 2023. It is now read-only.

Commit d91ac76

Browse files
author
Amir Khorsandi
committed
Add pageControl
1 parent fd6e8f2 commit d91ac76

File tree

8 files changed

+98
-7
lines changed

8 files changed

+98
-7
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "grayArrowLeft.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "grayArrowRight.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}

Samples/PagingLayoutSamples/Modules/LayoutDesigner/LayoutDesignerViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class LayoutDesignerViewModel {
2222
}
2323
var layouts: [ShapeLayout] = .stack
2424
var shapesViewModel: ShapesViewModel {
25-
ShapesViewModel(layouts: layouts, showBackButton: false)
25+
ShapesViewModel(layouts: layouts, showBackButton: false, showPageControl: true)
2626
}
2727
private(set) var optionViewModels: [LayoutDesignerOptionSectionViewModel] = []
2828
private let codeGenerator = OptionsCodeGenerator()

Samples/PagingLayoutSamples/Modules/Shapes/ShapesViewController.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ShapesViewController: UIViewController, NibBased, ViewModelBased {
3838
@IBOutlet private weak var backButton: UIButton!
3939
@IBOutlet private weak var collectionView: UICollectionView!
4040
@IBOutlet private weak var layoutTypeCollectionView: UICollectionView!
41+
@IBOutlet private weak var pageControlView: PageControlView!
4142

4243
private var didScrollCollectionViewToMiddle = false
4344

@@ -79,6 +80,14 @@ class ShapesViewController: UIViewController, NibBased, ViewModelBased {
7980
navigationController?.popViewController(animated: true)
8081
}
8182

83+
@IBAction private func onNextButtonTouched() {
84+
(collectionView.collectionViewLayout as? CollectionViewPagingLayout)?.goToNextPage()
85+
}
86+
87+
@IBAction private func onPreviousButtonTouched() {
88+
(collectionView.collectionViewLayout as? CollectionViewPagingLayout)?.goToPreviousPage()
89+
}
90+
8291

8392
// MARK: Private functions
8493

@@ -88,6 +97,10 @@ class ShapesViewController: UIViewController, NibBased, ViewModelBased {
8897
backButton.isHidden = !viewModel.showBackButton
8998
configureCollectionView()
9099
configureLayoutTypeCollectionView()
100+
101+
pageControlView.numberOfPages = 8
102+
pageControlView.preferences = .init(color: UIColor.black.withAlphaComponent(0.5), dimFactor: 0.2, dotRadius: 5, gapSize: 6, currentDotBorderWidth: 3.5)
103+
pageControlView.superview?.isHidden = !viewModel.showPageControl
91104
}
92105

93106
private func configureCollectionView() {
@@ -101,6 +114,7 @@ class ShapesViewController: UIViewController, NibBased, ViewModelBased {
101114
layout.numberOfVisibleItems = 10
102115
collectionView.collectionViewLayout = layout
103116
layout.configureTapOnCollectionView(goToSelectedPage: true)
117+
layout.delegate = self
104118
collectionView.showsHorizontalScrollIndicator = false
105119
collectionView.clipsToBounds = false
106120
collectionView.backgroundColor = .clear
@@ -229,3 +243,11 @@ extension ShapesViewController: UICollectionViewDelegate {
229243
updateSelectedLayout()
230244
}
231245
}
246+
247+
248+
extension ShapesViewController: CollectionViewPagingLayoutDelegate {
249+
func onCurrentPageChanged(layout: CollectionViewPagingLayout, currentPage: Int) {
250+
guard layout.collectionView == collectionView else { return }
251+
pageControlView.currentPage = currentPage
252+
}
253+
}

Samples/PagingLayoutSamples/Modules/Shapes/ShapesViewController.xib

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16086"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
66
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
77
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
88
</dependencies>
@@ -12,6 +12,7 @@
1212
<outlet property="backButton" destination="p26-Ln-ASY" id="xKW-ep-uc6"/>
1313
<outlet property="collectionView" destination="KcB-fn-Ojq" id="b1G-Kq-Mrc"/>
1414
<outlet property="layoutTypeCollectionView" destination="Lb2-15-Dq3" id="0FZ-em-Sll"/>
15+
<outlet property="pageControlView" destination="WIb-UY-Fc5" id="tyj-EK-9dy"/>
1516
<outlet property="view" destination="iN0-l3-epB" id="2vU-63-62s"/>
1617
</connections>
1718
</placeholder>
@@ -21,7 +22,7 @@
2122
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2223
<subviews>
2324
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="Lb2-15-Dq3">
24-
<rect key="frame" x="0.0" y="664" width="414" height="232"/>
25+
<rect key="frame" x="0.0" y="684" width="414" height="212"/>
2526
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
2627
<constraints>
2728
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="170" id="w5m-Ra-rqd"/>
@@ -34,7 +35,7 @@
3435
</collectionViewFlowLayout>
3536
</collectionView>
3637
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="KcB-fn-Ojq">
37-
<rect key="frame" x="0.0" y="93" width="414" height="571"/>
38+
<rect key="frame" x="0.0" y="113" width="414" height="571"/>
3839
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
3940
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="RPr-la-QPH">
4041
<size key="itemSize" width="50" height="50"/>
@@ -43,6 +44,44 @@
4344
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
4445
</collectionViewFlowLayout>
4546
</collectionView>
47+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="qGh-wo-gBe">
48+
<rect key="frame" x="87" y="54" width="240" height="40"/>
49+
<subviews>
50+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NKv-kr-wDf">
51+
<rect key="frame" x="0.0" y="4" width="32" height="32"/>
52+
<state key="normal" image="grayArrowLeft"/>
53+
<connections>
54+
<action selector="onPreviousButtonTouched" destination="-1" eventType="touchUpInside" id="ZYT-8R-7Rh"/>
55+
</connections>
56+
</button>
57+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="WIb-UY-Fc5" customClass="PageControlView" customModule="Paging_Layout" customModuleProvider="target">
58+
<rect key="frame" x="115" y="15" width="10" height="10"/>
59+
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
60+
<constraints>
61+
<constraint firstAttribute="width" priority="10" constant="10" id="2us-fF-sjt"/>
62+
<constraint firstAttribute="height" priority="10" constant="10" id="82g-tI-8Md"/>
63+
</constraints>
64+
</view>
65+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2QU-o5-0fg">
66+
<rect key="frame" x="207" y="4" width="33" height="32"/>
67+
<state key="normal" image="grayArrowRight"/>
68+
<connections>
69+
<action selector="onNextButtonTouched" destination="-1" eventType="touchUpInside" id="tYV-4c-sXU"/>
70+
</connections>
71+
</button>
72+
</subviews>
73+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
74+
<constraints>
75+
<constraint firstAttribute="trailing" secondItem="2QU-o5-0fg" secondAttribute="trailing" id="DQM-sU-mBl"/>
76+
<constraint firstItem="WIb-UY-Fc5" firstAttribute="centerY" secondItem="qGh-wo-gBe" secondAttribute="centerY" id="DeE-z9-lms"/>
77+
<constraint firstItem="NKv-kr-wDf" firstAttribute="centerY" secondItem="qGh-wo-gBe" secondAttribute="centerY" id="Dg1-N4-MBA"/>
78+
<constraint firstItem="NKv-kr-wDf" firstAttribute="leading" secondItem="qGh-wo-gBe" secondAttribute="leading" id="NMo-Rx-XsM"/>
79+
<constraint firstAttribute="height" constant="40" id="UEA-XN-aX4"/>
80+
<constraint firstAttribute="width" constant="240" id="f8V-2l-G3Y"/>
81+
<constraint firstItem="2QU-o5-0fg" firstAttribute="centerY" secondItem="qGh-wo-gBe" secondAttribute="centerY" id="hab-0E-gj9"/>
82+
<constraint firstItem="WIb-UY-Fc5" firstAttribute="centerX" secondItem="qGh-wo-gBe" secondAttribute="centerX" id="jyw-ev-6BB"/>
83+
</constraints>
84+
</view>
4685
<button opaque="NO" contentMode="scaleToFill" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" adjustsImageWhenHighlighted="NO" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="p26-Ln-ASY">
4786
<rect key="frame" x="32" y="63" width="23" height="20"/>
4887
<color key="backgroundColor" cocoaTouchSystemColor="lightTextColor"/>
@@ -60,14 +99,16 @@
6099
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
61100
<constraints>
62101
<constraint firstItem="KcB-fn-Ojq" firstAttribute="trailing" secondItem="vUN-kp-3ea" secondAttribute="trailing" id="BC1-4Z-Rtd"/>
102+
<constraint firstItem="qGh-wo-gBe" firstAttribute="centerX" secondItem="vUN-kp-3ea" secondAttribute="centerX" id="Che-Vh-LAB"/>
63103
<constraint firstItem="Lb2-15-Dq3" firstAttribute="top" secondItem="KcB-fn-Ojq" secondAttribute="bottom" id="FOb-g3-yTi"/>
64104
<constraint firstItem="Lb2-15-Dq3" firstAttribute="trailing" secondItem="vUN-kp-3ea" secondAttribute="trailing" id="Fdi-4x-9h8"/>
65105
<constraint firstItem="p26-Ln-ASY" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="19" id="Kcq-6Z-Niw"/>
66-
<constraint firstItem="KcB-fn-Ojq" firstAttribute="top" secondItem="p26-Ln-ASY" secondAttribute="bottom" constant="10" id="O7M-pd-eXi"/>
106+
<constraint firstItem="KcB-fn-Ojq" firstAttribute="top" secondItem="p26-Ln-ASY" secondAttribute="bottom" constant="30" id="O7M-pd-eXi"/>
67107
<constraint firstItem="Lb2-15-Dq3" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" id="R7O-fU-Gmo"/>
68108
<constraint firstAttribute="bottom" secondItem="Lb2-15-Dq3" secondAttribute="bottom" id="WX7-I4-6KC"/>
69109
<constraint firstItem="KcB-fn-Ojq" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" id="eq6-iY-n0D"/>
70110
<constraint firstItem="p26-Ln-ASY" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="32" id="rlv-DQ-Q8w"/>
111+
<constraint firstItem="qGh-wo-gBe" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="10" id="tVJ-Xi-1VW"/>
71112
<constraint firstItem="KcB-fn-Ojq" firstAttribute="height" secondItem="iN0-l3-epB" secondAttribute="height" multiplier="0.637" priority="900" id="tZ6-4E-M86"/>
72113
</constraints>
73114
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
@@ -76,5 +117,7 @@
76117
</objects>
77118
<resources>
78119
<image name="arrow.left.square.fill" catalog="system" width="128" height="114"/>
120+
<image name="grayArrowLeft" width="32" height="32"/>
121+
<image name="grayArrowRight" width="33" height="32"/>
79122
</resources>
80123
</document>

Samples/PagingLayoutSamples/Modules/Shapes/ShapesViewModel.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ class ShapesViewModel {
3333
}
3434
let layoutTypeViewModels: [LayoutTypeCellViewModel]
3535
let showBackButton: Bool
36+
let showPageControl: Bool
3637

3738

3839
// MARK: Lifecycle
3940

40-
init(layouts: [ShapeLayout], showBackButton: Bool = true) {
41+
init(layouts: [ShapeLayout], showBackButton: Bool = true, showPageControl: Bool = false) {
4142
self.showBackButton = showBackButton
43+
self.showPageControl = showPageControl
4244
self.layoutTypeViewModels = layouts.compactMap { layout in ShapesViewModel.allLayoutViewModes.first { $0.layout == layout } }
4345
selectedLayout = layoutTypeViewModels.first!
4446
}

0 commit comments

Comments
 (0)