-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathMiniNavigationBar.swift
97 lines (74 loc) · 2.93 KB
/
MiniNavigationBar.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// MiniNavigationBar.swift
// Recast
//
// Created by Jack Thompson on 10/28/18.
// Copyright © 2018 Cornell AppDev. All rights reserved.
//
import UIKit
/// Mini navigation bar that appears upon scroll of the `PodcastHeaderView` in `PodcastDetailViewController`.
class MiniNavigationBar: UIView {
var titleLabel: UILabel!
var subtitleLabel: UILabel!
var imageContainerView: UIView!
var backgroundImage: UIImageView!
var gradientLayer: CAGradientLayer!
static let height = 70 + UIApplication.shared.statusBarFrame.height
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .clear
layer.shadowColor = UIColor.black.cgColor
layer.shadowOffset = .zero
layer.shadowOpacity = 0.0
layer.shadowRadius = 6.0
imageContainerView = UIView()
imageContainerView.clipsToBounds = true
backgroundImage = UIImageView()
backgroundImage.clipsToBounds = true
backgroundImage.contentMode = .scaleAspectFill
imageContainerView.addSubview(backgroundImage)
gradientLayer = CAGradientLayer()
gradientLayer.colors = [UIColor(red: 51/255, green: 51/255, blue: 51/255, alpha: 0.9).cgColor, UIColor.black.cgColor]
gradientLayer.locations = [0.0, 0.9]
backgroundImage.layer.addSublayer(gradientLayer)
titleLabel = UILabel()
titleLabel.font = .boldSystemFont(ofSize: 22)
titleLabel.textColor = .white
titleLabel.textAlignment = .center
subtitleLabel = UILabel()
subtitleLabel.font = .systemFont(ofSize: 16)
subtitleLabel.textColor = .gray
subtitleLabel.textAlignment = .center
addSubview(imageContainerView)
addSubview(titleLabel)
addSubview(subtitleLabel)
setUpConstraints()
}
func setUpConstraints() {
let topPadding = UIApplication.shared.statusBarFrame.height + 5
let edgePadding = 36
let titleHeight = 30
let subtitleHeight = 21
let imageHeight: CGFloat = 374.5 + UIApplication.shared.statusBarFrame.height
imageContainerView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
backgroundImage.snp.makeConstraints { make in
make.top.leading.trailing.equalToSuperview()
make.height.equalTo(imageHeight)
}
titleLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(topPadding)
make.leading.trailing.equalToSuperview().inset(edgePadding)
make.height.equalTo(titleHeight)
}
subtitleLabel.snp.makeConstraints { make in
make.top.equalTo(titleLabel.snp.bottom)
make.leading.trailing.equalToSuperview().inset(edgePadding)
make.height.equalTo(subtitleHeight)
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}