Skip to content

Instantly share code, notes, and snippets.

@muizidn
Last active March 29, 2019 00:48
Show Gist options
  • Save muizidn/c760c0eea8fce5dd7e08bddfd0f0421e to your computer and use it in GitHub Desktop.
Save muizidn/c760c0eea8fce5dd7e08bddfd0f0421e to your computer and use it in GitHub Desktop.
Collection of Examples for ViewDSL
view.add { (scroll: UIScrollView) in
scroll.backgroundColor = .green
scroll.snp.makeConstraints { maker in
maker.edges.equalTo(view.snp.edges)
}
scroll.add { (v: UIView)in
v.backgroundColor = .red
/// Vertical Scrolling
v.snp.makeConstraints { maker in
maker.width.equalTo(scroll.snp.width).inset(10)
maker.centerX.equalTo(scroll.snp.centerX)
maker.top.equalTo(scroll.snp.top)
maker.bottom.equalTo(scroll.snp.bottom)
maker.height.equalTo(500)
// OR Use this if you want to make height dynamic
maker.centerY.equalTo(scroll.snp.centerY)
}
/// Horizontal Scrolling
v.snp.makeConstraints { maker in
maker.height.equalTo(scroll.snp.height).inset(10)
maker.centerY.equalTo(scroll.snp.centerY)
maker.left.equalTo(scroll.snp.left)
maker.right.equalTo(scroll.snp.right)
maker.width.equalTo(500)
// OR Use this if you want to make width dynamic
maker.centerX.equalTo(scroll.snp.centerX)
}
/// Scrollable View
v.snp.makeConstraints { maker in
maker.edges.equalTo(scroll.snp.edges)
maker.center.equalTo(scroll.snp.center)
maker.width.equalTo(500)
maker.height.equalTo(900)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment