Skip to content

Commit faef883

Browse files
author
RYUHEI KAMINISHI
committed
➕ Add examples
1 parent 70864e9 commit faef883

2 files changed

Lines changed: 52 additions & 14 deletions

File tree

Example/Example/Base.lproj/Main.storyboard

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@
2323
</constraints>
2424
</view>
2525
<stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="twq-hS-KKD">
26-
<rect key="frame" x="80" y="354" width="254" height="38"/>
26+
<rect key="frame" x="80" y="338" width="254" height="38"/>
2727
<subviews>
2828
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iiI-e1-BfA">
2929
<rect key="frame" x="0.0" y="0.0" width="84.5" height="38"/>
30-
<state key="normal" title="1"/>
30+
<state key="normal" title="0"/>
3131
<connections>
3232
<action selector="didTap1Button:" destination="BYZ-38-t0r" eventType="touchUpInside" id="5gg-ZK-qHH"/>
3333
</connections>
3434
</button>
3535
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Xdk-S4-KbX">
3636
<rect key="frame" x="84.5" y="0.0" width="85" height="38"/>
37-
<state key="normal" title="2"/>
37+
<state key="normal" title="1"/>
3838
<connections>
3939
<action selector="didTap2Button:" destination="BYZ-38-t0r" eventType="touchUpInside" id="hvM-GT-vBp"/>
4040
</connections>
4141
</button>
4242
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="pnQ-Or-PGT">
4343
<rect key="frame" x="169.5" y="0.0" width="84.5" height="38"/>
44-
<state key="normal" title="3"/>
44+
<state key="normal" title="2"/>
4545
<connections>
4646
<action selector="didTap3Button:" destination="BYZ-38-t0r" eventType="touchUpInside" id="hSc-g8-75K"/>
4747
</connections>
@@ -53,21 +53,43 @@
5353
<constraint firstItem="Xdk-S4-KbX" firstAttribute="width" secondItem="iiI-e1-BfA" secondAttribute="width" id="hX0-rc-sJJ"/>
5454
</constraints>
5555
</stackView>
56+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="RmS-uc-v2K" customClass="FloatingSegmentedControl" customModule="FloatingSegmentedControl">
57+
<rect key="frame" x="127" y="520" width="160" height="48"/>
58+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
59+
<constraints>
60+
<constraint firstAttribute="width" constant="160" id="GHo-GF-7Nb"/>
61+
<constraint firstAttribute="height" constant="48" id="mo2-Vp-2W5"/>
62+
</constraints>
63+
</view>
64+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5T1-kg-vpK" customClass="FloatingSegmentedControl" customModule="FloatingSegmentedControl">
65+
<rect key="frame" x="127" y="616" width="160" height="32"/>
66+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
67+
<constraints>
68+
<constraint firstAttribute="height" constant="32" id="17k-TD-72r"/>
69+
<constraint firstAttribute="width" constant="160" id="d0r-mT-ND2"/>
70+
</constraints>
71+
</view>
5672
</subviews>
57-
<color key="backgroundColor" systemColor="labelColor" cocoaTouchSystemColor="darkTextColor"/>
73+
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
5874
<constraints>
75+
<constraint firstItem="RmS-uc-v2K" firstAttribute="top" secondItem="rqd-4e-3Tx" secondAttribute="bottom" constant="48" id="886-p2-erl"/>
5976
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="rqd-4e-3Tx" secondAttribute="trailing" constant="16" id="9PL-TT-tEx"/>
6077
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="twq-hS-KKD" secondAttribute="trailing" constant="80" id="Art-gN-CIF"/>
61-
<constraint firstItem="rqd-4e-3Tx" firstAttribute="top" secondItem="twq-hS-KKD" secondAttribute="bottom" constant="32" id="Er0-XM-itb"/>
78+
<constraint firstItem="5T1-kg-vpK" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="CRv-Tq-C3p"/>
79+
<constraint firstItem="rqd-4e-3Tx" firstAttribute="top" secondItem="twq-hS-KKD" secondAttribute="bottom" constant="48" id="Er0-XM-itb"/>
6280
<constraint firstItem="twq-hS-KKD" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="80" id="RM6-I7-2QL"/>
81+
<constraint firstItem="5T1-kg-vpK" firstAttribute="top" secondItem="RmS-uc-v2K" secondAttribute="bottom" constant="48" id="ZM5-3r-uxQ"/>
6382
<constraint firstItem="rqd-4e-3Tx" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="bIa-KP-Nz0"/>
6483
<constraint firstItem="rqd-4e-3Tx" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="cv6-8o-Ito"/>
84+
<constraint firstItem="RmS-uc-v2K" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="uc1-Iu-qkM"/>
6585
<constraint firstItem="rqd-4e-3Tx" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="vnq-AJ-4Vp"/>
6686
</constraints>
6787
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
6888
</view>
6989
<connections>
70-
<outlet property="control" destination="rqd-4e-3Tx" id="T24-IB-t3O"/>
90+
<outlet property="segmentedControl1" destination="rqd-4e-3Tx" id="T24-IB-t3O"/>
91+
<outlet property="segmentedControl2" destination="RmS-uc-v2K" id="MRv-th-2bJ"/>
92+
<outlet property="segmentedControl3" destination="5T1-kg-vpK" id="fPS-Ka-GPn"/>
7193
</connections>
7294
</viewController>
7395
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>

Example/Example/ViewController.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,44 @@ import FloatingSegmentedControl
1111

1212
final class ViewController: UIViewController {
1313

14-
@IBOutlet private weak var control: FloatingSegmentedControl!
14+
@IBOutlet private weak var segmentedControl1: FloatingSegmentedControl!
15+
@IBOutlet private weak var segmentedControl2: FloatingSegmentedControl!
16+
@IBOutlet private weak var segmentedControl3: FloatingSegmentedControl!
1517

1618
override func viewDidLoad() {
1719
super.viewDidLoad()
1820

19-
control.setSegments(with: [
21+
segmentedControl1.setSegments(with: [
2022
"Today", "Days", "Months"
2123
])
22-
control.addTarget(self, action: #selector(update(_:)))
23-
control.isAnimateFocusMoving = true
24+
segmentedControl1.addTarget(self, action: #selector(update(_:)))
25+
segmentedControl1.isAnimateFocusMoving = true
26+
27+
segmentedControl2.setSegments(with: [
28+
"Left", "Right"
29+
])
30+
31+
segmentedControl2.addTarget(self, action: #selector(update(_:)))
32+
segmentedControl2.isAnimateFocusMoving = true
33+
34+
segmentedControl3.setSegments(with: [
35+
"Left", "Right"
36+
])
37+
38+
segmentedControl3.addTarget(self, action: #selector(update(_:)))
39+
segmentedControl3.isAnimateFocusMoving = true
2440
}
2541

2642
@IBAction func didTap1Button(_ sender: Any) {
27-
control.move(to: 0)
43+
segmentedControl1.move(to: 0)
2844
}
2945

3046
@IBAction func didTap2Button(_ sender: Any) {
31-
control.move(to: 1)
47+
segmentedControl1.move(to: 1)
3248
}
3349

3450
@IBAction func didTap3Button(_ sender: Any) {
35-
control.move(to: 2)
51+
segmentedControl1.move(to: 2)
3652
}
3753

3854
@objc func update(_ sender: FloatingSegmentedControl) {

0 commit comments

Comments
 (0)