@@ -12,20 +12,29 @@ import ScrollableStackView
1212class 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) )
0 commit comments