Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example usage of layout([views]) #42

Closed
jimjeffers opened this issue Dec 5, 2014 · 1 comment
Closed

Example usage of layout([views]) #42

jimjeffers opened this issue Dec 5, 2014 · 1 comment

Comments

@jimjeffers
Copy link

Hey there,

I was wondering if there's a quick snippet handy which could illustrate the usage of the layout method accepting an arbitrary array of views (https://github.com/robb/Cartography/blob/master/Cartography/Layout.swift#L32) as opposed to a fixed amount. I'm still new to swift so I'm having trouble understanding how to use this method.

@jimjeffers
Copy link
Author

Nevermind. Spoke to soon. Some more fooling around and I realized it was trivial. Sorry about that. Here's a quick snippet as an example.

layout([UIView(), UIView(), UIView(), UIView(), UIView()]) { (views) -> () in

    // Pin first and last views to edges.
    views[0].left               == views[0].superview!.left
    views[views.count-1].right  == views[views.count-1].superview!.right

    for (index, view) in enumerate(views) {

        // All views should match the height of their parent
        view.top                == view.superview!.top
        view.bottom             == view.superview!.bottom

        if(index > 0) {
            // All views should be the same width.
            view.width          == views[index-1].width

            // All views should be 2dp apart
            view.left           == views[index-1].right + 2 ~ 400
        }

    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant