Created
May 4, 2017 14:46
-
-
Save yudetamago/e3c511d6d955059e071fda216678edcc to your computer and use it in GitHub Desktop.
UIScrollView with SnapKit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import SnapKit | |
func setScrollView(content: UIView) { | |
// called in ViewController | |
self.edgesForExtendedLayout = [] | |
let scrollView = UIScrollView() | |
let wrapper = UIView() | |
self.view.addSubview(scrollView) | |
scrollView.addSubview(wrapper) | |
wrapper.addSubview(content) | |
content.snp.makeConstraints { make in | |
make.edges.equalToSuperview() | |
} | |
scrollView.snp.makeConstraints { make in | |
make.top.equalTo(topLayoutGuide.snp.bottom) | |
make.bottom.equalToSuperview() | |
make.width.equalToSuperview() | |
} | |
wrapper.snp.makeConstraints { make in | |
make.edges.equalToSuperview() | |
// only vertical scroll | |
make.width.equalToSuperview() | |
// only horizontal scroll | |
//make.height.equalToSuperview() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why do you need wrapper? Can't you add the
content
view directly toscrollView
?