Skip to content

Commit

Permalink
Example update. Added UILabel.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gürhan Yerlikaya committed Dec 19, 2016
1 parent 7c1a080 commit 5646a73
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Example/ScrollableStackView/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-44.927536231884062" y="134.5108695652174"/>
<point key="canvasLocation" x="33" y="33"/>
</scene>
</scenes>
</document>
19 changes: 16 additions & 3 deletions Example/ScrollableStackView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,29 @@ class ViewController: UIViewController {
super.viewDidLoad()

scrollable = ScrollableStackView(frame: view.frame)
scrollable.stackView.distribution = .fillProportionally
scrollable.stackView.alignment = .center
scrollable.stackView.axis = .vertical
view.addSubview(scrollable)

for _ in 1 ..< 11 {
let random = CGFloat(arc4random_uniform(131) + 30) // between 30-130
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: 42, height: 42))
let min:UInt32 = 30
let max:UInt32 = 400
let random = CGFloat(arc4random_uniform(max - min) + min) // between 30-130
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: random, height: random))
rectangle.backgroundColor = UIColor(red: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1.0)
rectangle.heightAnchor.constraint(equalToConstant: random).isActive = true
rectangle.widthAnchor.constraint(equalToConstant: random).isActive = true
scrollable.stackView.addArrangedSubview(rectangle)
}

let label = UILabel(frame: CGRect(x: 0, y: 0, width: 350, height: 45))
label.numberOfLines = 0
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."

label.sizeToFit()
scrollable.stackView.addArrangedSubview(label)

view.setNeedsUpdateConstraints()
}

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

didSetupConstraints = true
}

super.updateViewConstraints()
}

Expand Down
2 changes: 1 addition & 1 deletion ScrollableStackView/Classes/ScrollableStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import UIKit

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

Expand Down

0 comments on commit 5646a73

Please sign in to comment.