class StackScrollView: UIScrollView {
private(set) lazy var stack: UIStackView = {
let stack = UIStackView()
stack.axis = .vertical
stack.alignment = .center
return stack
}()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(stack)
stack.snp.makeConstraints { (make) in
make.top.equalTo(self)
make.left.equalTo(self)
make.right.equalTo(self)
make.centerX.equalTo(self)
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
contentSize = stack.frame.size
}
func push(view: UIView) {
stack.addArrangedSubview(view)
}
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme