@@ -27,6 +27,7 @@ import UIKit
2727 // ScrollView
2828 scrollView = UIScrollView ( frame: self . frame)
2929 scrollView. translatesAutoresizingMaskIntoConstraints = false
30+ scrollView. layoutMargins = . zero
3031 self . addSubview ( scrollView)
3132
3233 // StackView
@@ -114,14 +115,17 @@ import UIKit
114115 super. updateConstraints ( )
115116
116117 if ( !didSetupConstraints) {
117- self . addConstraint ( NSLayoutConstraint ( item: scrollView, attribute: . left, relatedBy: . equal, toItem: self , attribute: . left, multiplier: 1.0 , constant: 0 ) )
118- self . addConstraint ( NSLayoutConstraint ( item: scrollView, attribute: . right, relatedBy: . equal, toItem: self , attribute: . right, multiplier: 1.0 , constant: 0 ) )
118+ addConstraint ( NSLayoutConstraint ( item: scrollView, attribute: . left, relatedBy: . equal, toItem: self , attribute: . left, multiplier: 1.0 , constant: 0 ) )
119+ addConstraint ( NSLayoutConstraint ( item: scrollView, attribute: . right, relatedBy: . equal, toItem: self , attribute: . right, multiplier: 1.0 , constant: 0 ) )
119120
120- self . addConstraint ( NSLayoutConstraint ( item: scrollView, attribute: . bottom, relatedBy: . equal, toItem: self , attribute: . bottom, multiplier: 1.0 , constant: 0 ) )
121- self . addConstraint ( NSLayoutConstraint ( item: scrollView, attribute: . top, relatedBy: . equal, toItem: self , attribute: . top, multiplier: 1.0 , constant: 0 ) )
121+ addConstraint ( NSLayoutConstraint ( item: scrollView, attribute: . bottom, relatedBy: . equal, toItem: self , attribute: . bottom, multiplier: 1.0 , constant: 0 ) )
122+ addConstraint ( NSLayoutConstraint ( item: scrollView, attribute: . top, relatedBy: . equal, toItem: self , attribute: . top, multiplier: 1.0 , constant: 0 ) )
122123
123- self . addConstraints ( NSLayoutConstraint . constraints ( withVisualFormat: " H:[stackView(==scrollView)] " , options: . alignAllCenterX, metrics: nil , views: [ " stackView " : stackView, " scrollView " : scrollView] ) )
124- self . addConstraints ( NSLayoutConstraint . constraints ( withVisualFormat: " V:|[stackView]| " , options: . alignAllCenterX, metrics: nil , views: [ " stackView " : stackView] ) )
124+ addConstraints ( NSLayoutConstraint . constraints ( withVisualFormat: " V:|-[stackView]-| " , options: [ ] , metrics: nil , views: [ " stackView " : stackView] ) )
125+
126+ let margins = scrollView. layoutMarginsGuide
127+ stackView. leadingAnchor. constraint ( equalTo: margins. leadingAnchor) . isActive = true
128+ stackView. trailingAnchor. constraint ( equalTo: margins. trailingAnchor) . isActive = true
125129
126130 didSetupConstraints = true
127131 }
0 commit comments