Skip to content

Commit 5646a73

Browse files
author
Gürhan Yerlikaya
committed
Example update. Added UILabel.
1 parent 7c1a080 commit 5646a73

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Example/ScrollableStackView/Base.lproj/Main.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</viewController>
2525
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
2626
</objects>
27-
<point key="canvasLocation" x="-44.927536231884062" y="134.5108695652174"/>
27+
<point key="canvasLocation" x="33" y="33"/>
2828
</scene>
2929
</scenes>
3030
</document>

Example/ScrollableStackView/ViewController.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,29 @@ class ViewController: UIViewController {
1818
super.viewDidLoad()
1919

2020
scrollable = ScrollableStackView(frame: view.frame)
21+
scrollable.stackView.distribution = .fillProportionally
22+
scrollable.stackView.alignment = .center
23+
scrollable.stackView.axis = .vertical
2124
view.addSubview(scrollable)
2225

2326
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))
27+
let min:UInt32 = 30
28+
let max:UInt32 = 400
29+
let random = CGFloat(arc4random_uniform(max - min) + min) // between 30-130
30+
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: random, height: random))
2631
rectangle.backgroundColor = UIColor(red: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1.0)
2732
rectangle.heightAnchor.constraint(equalToConstant: random).isActive = true
33+
rectangle.widthAnchor.constraint(equalToConstant: random).isActive = true
2834
scrollable.stackView.addArrangedSubview(rectangle)
2935
}
3036

37+
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 350, height: 45))
38+
label.numberOfLines = 0
39+
label.text = "Build with Xcode 8 and the latest SDKs. Xcode 8 includes Swift 3 and the latest SDKs for all Apple platforms. If your app is written in Swift, you can submit your apps to the App Store written in either Swift 3.0 or 2.3. We strongly encourage you to migrate your code to Swift 3. However, if you need to first update your code to Swift 2.3, you can run the Xcode 8 migrator later to move from 2.3 to 3.0. Before finalizing your app for release to the general public, get valuable feedback with beta testing to make sure it’s ready for your customers. TestFlight makes it easy to invite users to beta test your apps directly on their iPhone, iPad, Apple Watch, and Apple TV."
40+
41+
label.sizeToFit()
42+
scrollable.stackView.addArrangedSubview(label)
43+
3144
view.setNeedsUpdateConstraints()
3245
}
3346

@@ -41,7 +54,7 @@ class ViewController: UIViewController {
4154

4255
didSetupConstraints = true
4356
}
44-
57+
4558
super.updateViewConstraints()
4659
}
4760

ScrollableStackView/Classes/ScrollableStackView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import UIKit
5252

5353
func addItemToStack() {
5454
let random = CGFloat(arc4random_uniform(131) + 30) // between 30-130
55-
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: 42, height: 42))
55+
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: random, height: random))
5656
rectangle.backgroundColor = UIColor(red: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1.0)
5757
rectangle.heightAnchor.constraint(equalToConstant: random).isActive = true
5858

0 commit comments

Comments
 (0)