robb / Cartography

A declarative Auto Layout DSL for Swift :iphone::triangular_ruler:
Other
7.34k stars 525 forks source link

adding more than 5 views in the constrain closure #263

Open ghost opened 7 years ago

ghost commented 7 years ago

how can i add more than 5 views in the constrain

bryanjclark commented 6 years ago

@pprevalon To ad more than 5, you can pass in an array of objects, and then unpack that array inside the closure. Here's an extreme example from the KA app:

constrain([container, googleButton, facebookButton, orLabel, textBackground, textSeparator, usernameField, passwordField, forgotButton, passwordManagerLoginButton, signInButton, errorLabel]) { proxies in
            let (container, googleButton, facebookButton, orLabel, textBackground, textSeparator, usernameField, passwordField, forgotButton, passwordManagerLoginButton, signInButton, errorLabel) = (proxies[0], proxies[1], proxies[2], proxies[3], proxies[4], proxies[5], proxies[6], proxies[7], proxies[8], proxies[9], proxies[10], proxies[11])
            let itemWidth: CGFloat = 256
            let itemHeight: CGFloat = 48
            let buttonSpacing = SignInDefaultView.buttonSpacing
            let forgotButtonMargin: CGFloat = 14

            errorLabel.centerX == container.centerX
            errorLabel.width == itemWidth
            errorLabel.bottom == googleButton.top - buttonSpacing

            googleButton.centerX == container.centerX
            googleButton.width == itemWidth
            googleButton.height == itemHeight

                        // etc
}
bryanjclark commented 6 years ago

See also the discussion over here: https://github.com/robb/Cartography/issues/197

ghost commented 6 years ago

Thank you a million