-
Notifications
You must be signed in to change notification settings - Fork 2
/
StackScrollable.swift
68 lines (55 loc) · 2.02 KB
/
StackScrollable.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// StackScrollable.swift
// VStack
//
// Created by Matheus Fróes on 01/07/19.
// Copyright © 2019 Matheus Fróes. All rights reserved.
//
import Foundation
import UIKit
final class StackScrollable: UIScrollView {
private lazy var containerView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
private(set) lazy var stack: Stack = {
let stack = Stack()
stack.translatesAutoresizingMaskIntoConstraints = false
return stack
}()
init() {
super.init(frame: .zero)
setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupViews() {
translatesAutoresizingMaskIntoConstraints = false
setupContainerView()
setupStack()
}
private func setupContainerView() {
addSubview(containerView)
let heightConstraint = containerView.heightAnchor.constraint(equalTo: heightAnchor)
heightConstraint.priority = .init(750)
NSLayoutConstraint.activate([
containerView.leadingAnchor.constraint(equalTo: leadingAnchor),
containerView.trailingAnchor.constraint(equalTo: trailingAnchor),
containerView.topAnchor.constraint(equalTo: topAnchor),
containerView.bottomAnchor.constraint(equalTo: bottomAnchor),
containerView.widthAnchor.constraint(equalTo: widthAnchor),
heightConstraint
])
}
private func setupStack() {
containerView.addSubview(stack)
NSLayoutConstraint.activate([
stack.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
stack.trailingAnchor.constraint(equalTo: containerView.trailingAnchor),
stack.topAnchor.constraint(equalTo: containerView.topAnchor),
stack.bottomAnchor.constraint(equalTo: containerView.bottomAnchor)
])
}
}