-
Notifications
You must be signed in to change notification settings - Fork 37
/
HomeCollectionViewHeader.swift
76 lines (61 loc) · 2.23 KB
/
HomeCollectionViewHeader.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
69
70
71
72
73
74
75
76
//
// HomeTableViewHeaderView.swift
// Recast
//
// Created by Jaewon Sim on 9/17/18.
// Copyright © 2018 Cornell AppDev. All rights reserved.
//
import UIKit
protocol HomeTableViewHeaderViewDelegate: class {
func homeTableViewHeaderView(_ tableHeader: HomeCollectionViewHeader, didPress: Action)
}
/// Represents an action that can be performed on a button
enum Action {
case seeAll
}
class HomeCollectionViewHeader: UICollectionReusableView {
// MARK: View vars
var headerTitleLabel: UILabel!
var seeAllButton: UIButton!
// MARK: Delegate
weak var delegate: HomeTableViewHeaderViewDelegate?
// MARK: Lifecycle
override init(frame: CGRect) {
super.init(frame: frame)
headerTitleLabel = UILabel()
headerTitleLabel.font = UIFont.systemFont(ofSize: 22, weight: .bold)
headerTitleLabel.textColor = .white
addSubview(headerTitleLabel)
seeAllButton = UIButton(type: .system)
seeAllButton.setTitle("See all", for: .normal)
seeAllButton.titleLabel?.font = UIFont.systemFont(ofSize: 12)
seeAllButton.setTitleColor(.white, for: .normal)
seeAllButton.isEnabled = true
seeAllButton.addTarget(self, action: #selector(didPressSeeAll), for: .touchUpInside)
addSubview(seeAllButton)
setUpConstraints()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: Constraint setup
func setUpConstraints() {
// MARK: Constraint constants
let sidePadding: CGFloat = 22
let bottomPadding: CGFloat = 12
let seeAllButtonWidth: CGFloat = 40
headerTitleLabel.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(sidePadding)
make.bottom.equalToSuperview().offset(-bottomPadding)
}
seeAllButton.snp.makeConstraints { make in
make.centerY.equalTo(headerTitleLabel)
make.trailing.equalToSuperview().inset(sidePadding)
make.height.equalTo(headerTitleLabel.snp.height)
make.width.equalTo(seeAllButtonWidth)
}
}
@objc func didPressSeeAll() {
delegate?.homeTableViewHeaderView(self, didPress: .seeAll)
}
}