Skip to content

Commit 47e3fb4

Browse files
author
Gürhan Yerlikaya
committed
example updated
1 parent f2cee5e commit 47e3fb4

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

Example/ScrollableStackView/Base.lproj/Main.storyboard

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3+
<device id="retina5_5" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
7+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
8+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
59
</dependencies>
610
<scenes>
711
<!--View Controller-->
812
<scene sceneID="ufC-wZ-h7g">
913
<objects>
10-
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
14+
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="ScrollableStackView_Example" customModuleProvider="target" sceneMemberID="viewController">
1115
<layoutGuides>
1216
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
1317
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
1418
</layoutGuides>
1519
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
16-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
20+
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
1721
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
18-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
22+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
1923
</view>
2024
</viewController>
2125
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>

Example/ScrollableStackView/ViewController.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,29 @@ import ScrollableStackView
1212
class ViewController: UIViewController {
1313

1414
var didSetupConstraints = false
15-
var scrollableStackView: ScrollableStackView!
15+
var scrollable: ScrollableStackView!
1616

1717
override func viewDidLoad() {
1818
super.viewDidLoad()
1919

20-
scrollableStackView = ScrollableStackView(frame: view.frame)
21-
view.addSubview(scrollableStackView)
20+
scrollable = ScrollableStackView(frame: view.frame)
21+
view.addSubview(scrollable)
22+
23+
for _ in 1 ..< 11 {
24+
let random = CGFloat(arc4random_uniform(131) + 30) // between 30-130
25+
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: 42, height: 42))
26+
rectangle.backgroundColor = UIColor(red: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1.0)
27+
rectangle.heightAnchor.constraint(equalToConstant: random).isActive = true
28+
scrollable.stackView.addArrangedSubview(rectangle)
29+
}
30+
2231
view.setNeedsUpdateConstraints()
2332
}
2433

2534
override func updateViewConstraints() {
2635
if (!didSetupConstraints) {
2736

28-
let views:[String: AnyObject] = ["scrollableStackView": scrollableStackView]
37+
let views:[String: AnyObject] = ["scrollableStackView": scrollable]
2938

3039
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[scrollableStackView]|", options: .alignAllCenterX, metrics: nil, views: views))
3140
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[scrollableStackView]|", options: .alignAllCenterX, metrics: nil, views: views))

ScrollableStackView/Classes/ScrollableStackView.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ import UIKit
3737
stackView.distribution = .equalSpacing
3838
scrollView.addSubview(stackView)
3939

40-
for _ in 1 ..< 11 {
41-
let random = CGFloat(arc4random_uniform(131) + 30) // between 30-130
42-
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: 42, height: 42))
43-
rectangle.backgroundColor = UIColor(red: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1.0)
44-
rectangle.heightAnchor.constraint(equalToConstant: random).isActive = true
45-
stackView.addArrangedSubview(rectangle)
46-
}
47-
4840
self.setNeedsUpdateConstraints() // Bootstrap auto layout
4941
}
5042

0 commit comments

Comments
 (0)