Skip to content

Instantly share code, notes, and snippets.

@Kalvin126
Last active January 25, 2018 20:30
Show Gist options
  • Save Kalvin126/4863703b72f434f2db2796a150283378 to your computer and use it in GitHub Desktop.
Save Kalvin126/4863703b72f434f2db2796a150283378 to your computer and use it in GitHub Desktop.
import SnapKit
import UIKit
// MARK: - AutoLayout
extension UIView {
@discardableResult func addSubview<View: UIView>(_ subview: View, constraintMaker: (View, ConstraintMaker) -> Void) -> View {
subview.translatesAutoresizingMaskIntoConstraints = false
addSubview(subview)
subview.snp.makeConstraints { constraintMaker(subview, $0) }
return subview
}
}
@Kalvin126
Copy link
Author

override func viewDidLoad() {
	super.viewDidLoad()

	let stackView = UIStackView(arrangedSubviews: [/*views*/])

	view.addSubview(stackView) { view, make in
		view.alignment = .fill
		
		make.top.left.right.equalToSuperView()
	}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment