Skip to content

Commit 6cd54f8

Browse files
committed
Add Sample
1 parent 0196abf commit 6cd54f8

File tree

8 files changed

+497
-2
lines changed

8 files changed

+497
-2
lines changed

Cartfile.private

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// AppDelegate.swift
3+
// StackScrollView-Demo
4+
//
5+
// Created by muukii on 9/18/16.
6+
// Copyright © 2016 muukii. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
@UIApplicationMain
12+
class AppDelegate: UIResponder, UIApplicationDelegate {
13+
14+
var window: UIWindow?
15+
16+
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
18+
// Override point for customization after application launch.
19+
return true
20+
}
21+
22+
func applicationWillResignActive(_ application: UIApplication) {
23+
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24+
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
25+
}
26+
27+
func applicationDidEnterBackground(_ application: UIApplication) {
28+
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30+
}
31+
32+
func applicationWillEnterForeground(_ application: UIApplication) {
33+
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
34+
}
35+
36+
func applicationDidBecomeActive(_ application: UIApplication) {
37+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38+
}
39+
40+
func applicationWillTerminate(_ application: UIApplication) {
41+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42+
}
43+
44+
45+
}
46+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "29x29",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "29x29",
11+
"scale" : "3x"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"size" : "40x40",
16+
"scale" : "2x"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"size" : "40x40",
21+
"scale" : "3x"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"size" : "60x60",
26+
"scale" : "2x"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"size" : "60x60",
31+
"scale" : "3x"
32+
}
33+
],
34+
"info" : {
35+
"version" : 1,
36+
"author" : "xcode"
37+
}
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
5+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6+
</dependencies>
7+
<scenes>
8+
<!--View Controller-->
9+
<scene sceneID="EHf-IW-A2E">
10+
<objects>
11+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
12+
<layoutGuides>
13+
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
14+
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
15+
</layoutGuides>
16+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
17+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
20+
</view>
21+
</viewController>
22+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
23+
</objects>
24+
<point key="canvasLocation" x="53" y="375"/>
25+
</scene>
26+
</scenes>
27+
</document>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
5+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6+
</dependencies>
7+
<scenes>
8+
<!--View Controller-->
9+
<scene sceneID="tne-QT-ifu">
10+
<objects>
11+
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
12+
<layoutGuides>
13+
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
14+
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
15+
</layoutGuides>
16+
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
17+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
20+
</view>
21+
</viewController>
22+
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
23+
</objects>
24+
</scene>
25+
</scenes>
26+
</document>

StackScrollView-Demo/Info.plist

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
<key>LSRequiresIPhoneOS</key>
22+
<true/>
23+
<key>UILaunchStoryboardName</key>
24+
<string>LaunchScreen</string>
25+
<key>UIMainStoryboardFile</key>
26+
<string>Main</string>
27+
<key>UIRequiredDeviceCapabilities</key>
28+
<array>
29+
<string>armv7</string>
30+
</array>
31+
<key>UISupportedInterfaceOrientations</key>
32+
<array>
33+
<string>UIInterfaceOrientationPortrait</string>
34+
<string>UIInterfaceOrientationLandscapeLeft</string>
35+
<string>UIInterfaceOrientationLandscapeRight</string>
36+
</array>
37+
</dict>
38+
</plist>
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
//
2+
// ViewController.swift
3+
// StackScrollView
4+
//
5+
// Created by muukii on 08/29/2016.
6+
// Copyright (c) 2016 muukii. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
import StackScrollView
12+
import EasyPeasy
13+
14+
import Then
15+
16+
class ViewController: UIViewController {
17+
18+
override func viewDidLoad() {
19+
super.viewDidLoad()
20+
21+
let colorA = UIColor(white: 0.9, alpha: 1)
22+
let colorB = UIColor(white: 0.8, alpha: 1)
23+
24+
25+
let labelCell = LabelStackViewCell().then { cell in
26+
cell.backgroundColor = colorA
27+
cell.titleLabel.text = "Hiroshi"
28+
cell.detailLabel.text = "Kimura"
29+
}
30+
31+
let switchCell = SwitchStackViewCell().then { cell in
32+
cell.backgroundColor = colorB
33+
cell.titleLabel.text = "Hiroshi"
34+
cell.valueChanged = { on in
35+
36+
}
37+
}
38+
39+
let labelFromTextCell = LabelStackViewCell().then { cell in
40+
cell.backgroundColor = colorA
41+
cell.titleLabel.text = "Hiroshi"
42+
cell.detailLabel.text = "Kimura"
43+
}
44+
45+
let textFieldCell = TextFieldStackViewCell().then { cell in
46+
cell.backgroundColor = colorB
47+
cell.titleLabel.text = "Hiroshi"
48+
cell.valueChanged = { string in
49+
50+
labelFromTextCell.titleLabel.text = string
51+
}
52+
}
53+
54+
stackScrollView.append(
55+
views: [
56+
labelCell,
57+
switchCell,
58+
labelFromTextCell,
59+
textFieldCell,
60+
],
61+
animated: true)
62+
}
63+
64+
override func didReceiveMemoryWarning() {
65+
super.didReceiveMemoryWarning()
66+
// Dispose of any resources that can be recreated.
67+
}
68+
69+
@IBOutlet weak var stackScrollView: StackScrollView!
70+
}
71+
72+
class LabelStackViewCell: UIView {
73+
74+
init() {
75+
super.init(frame: .zero)
76+
77+
addSubview(titleLabel)
78+
addSubview(detailLabel)
79+
80+
titleLabel <- [
81+
Left(8),
82+
CenterY(),
83+
]
84+
85+
detailLabel <- [
86+
Right(8),
87+
CenterY(),
88+
]
89+
}
90+
91+
override func intrinsicContentSize() -> CGSize {
92+
return CGSize(width: UIViewNoIntrinsicMetric, height: 60)
93+
}
94+
95+
required init?(coder aDecoder: NSCoder) {
96+
fatalError("init(coder:) has not been implemented")
97+
}
98+
99+
let titleLabel = UILabel()
100+
let detailLabel = UILabel()
101+
}
102+
103+
class SwitchStackViewCell: UIView {
104+
105+
var valueChanged: (Bool) -> Void = { _ in }
106+
107+
init() {
108+
super.init(frame: .zero)
109+
110+
addSubview(titleLabel)
111+
addSubview(switchView)
112+
113+
titleLabel <- [
114+
Left(8),
115+
CenterY(),
116+
]
117+
118+
switchView <- [
119+
Right(8),
120+
CenterY(),
121+
]
122+
123+
switchView.addTarget(self, action: #selector(switchValueChanged), forControlEvents: .ValueChanged)
124+
}
125+
126+
override func intrinsicContentSize() -> CGSize {
127+
return CGSize(width: UIViewNoIntrinsicMetric, height: 60)
128+
}
129+
130+
required init?(coder aDecoder: NSCoder) {
131+
fatalError("init(coder:) has not been implemented")
132+
}
133+
134+
let titleLabel = UILabel()
135+
136+
let switchView = UISwitch()
137+
138+
@objc private func switchValueChanged() {
139+
140+
valueChanged(switchView.on)
141+
}
142+
}
143+
144+
class TextFieldStackViewCell: UIView {
145+
146+
var valueChanged: (String) -> Void = { _ in }
147+
148+
init() {
149+
super.init(frame: .zero)
150+
151+
addSubview(titleLabel)
152+
addSubview(textField)
153+
154+
titleLabel.setContentHuggingPriority(950, forAxis: .Horizontal)
155+
titleLabel <- [
156+
Left(8),
157+
CenterY(),
158+
]
159+
160+
textField <- [
161+
Left(8).to(titleLabel, .Right),
162+
Right(8),
163+
CenterY(),
164+
]
165+
166+
textField.backgroundColor = UIColor(white: 0, alpha: 0.5)
167+
168+
textField.addTarget(self, action: #selector(textChanged), forControlEvents: .EditingChanged)
169+
}
170+
171+
override func intrinsicContentSize() -> CGSize {
172+
return CGSize(width: UIViewNoIntrinsicMetric, height: 60)
173+
}
174+
175+
required init?(coder aDecoder: NSCoder) {
176+
fatalError("init(coder:) has not been implemented")
177+
}
178+
179+
let titleLabel = UILabel()
180+
181+
let textField = UITextField()
182+
183+
@objc private func textChanged() {
184+
185+
valueChanged(textField.text ?? "")
186+
}
187+
}

0 commit comments

Comments
 (0)