Commit ac9ecdf7 by Dmitriy Stepanets

Added forecest details cell

parent 1ece4c23
No preview for this file type
......@@ -15,6 +15,7 @@
CD1237DE255D612300C98139 /* CurrentForecastCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1237DD255D612300C98139 /* CurrentForecastCell.swift */; };
CD1237F1255D83C500C98139 /* UIColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1237F0255D83C500C98139 /* UIColor+Hex.swift */; };
CD1237F4255D889F00C98139 /* GradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1237F3255D889F00C98139 /* GradientView.swift */; };
CDCC480E255EA8D2003EA8A7 /* CurrentForecastDetailsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCC480D255EA8D2003EA8A7 /* CurrentForecastDetailsCell.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
......@@ -30,6 +31,7 @@
CD1237DD255D612300C98139 /* CurrentForecastCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentForecastCell.swift; sourceTree = "<group>"; };
CD1237F0255D83C500C98139 /* UIColor+Hex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Hex.swift"; sourceTree = "<group>"; };
CD1237F3255D889F00C98139 /* GradientView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientView.swift; sourceTree = "<group>"; };
CDCC480D255EA8D2003EA8A7 /* CurrentForecastDetailsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentForecastDetailsCell.swift; sourceTree = "<group>"; };
DF826CF4702D9DCCB9A9DD71 /* Pods-1Weather.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-1Weather.release.xcconfig"; path = "Target Support Files/Pods-1Weather/Pods-1Weather.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -91,6 +93,7 @@
CD1237DC255D60EC00C98139 /* Cells */ = {
isa = PBXGroup;
children = (
CDCC480D255EA8D2003EA8A7 /* CurrentForecastDetailsCell.swift */,
CD1237DD255D612300C98139 /* CurrentForecastCell.swift */,
);
path = Cells;
......@@ -233,6 +236,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CDCC480E255EA8D2003EA8A7 /* CurrentForecastDetailsCell.swift in Sources */,
CD1237C7255D5C5900C98139 /* ViewController.swift in Sources */,
CD1237F1255D83C500C98139 /* UIColor+Hex.swift in Sources */,
CD1237F4255D889F00C98139 /* GradientView.swift in Sources */,
......
......@@ -35,6 +35,7 @@ class CurrentForecastCell: UITableViewCell {
}
}
//MARK:- Prepare
private extension CurrentForecastCell {
func prepareCell() {
contentView.backgroundColor = .clear
......
//
// CurrentForecastDetailsCell.swift
// 1Weather
//
// Created by Dmitry Stepanets on 13.11.2020.
//
import UIKit
private class InfoCardView:UIView {
private let valueLabel = UILabel()
private let titleLabel = UILabel()
init(title:String, value:String) {
super.init(frame: .zero)
self.titleLabel.text = title
self.valueLabel.text = value
prepare()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func prepare() {
valueLabel.font = UIFont.boldSystemFont(ofSize: 18)
valueLabel.textColor = .white
addSubview(valueLabel)
valueLabel.snp.makeConstraints { (make) in
make.top.equalToSuperview().inset(16)
make.centerX.equalToSuperview()
}
titleLabel.font = UIFont.systemFont(ofSize: 13, weight: .medium)
titleLabel.textColor = .white
titleLabel.textAlignment = .center
addSubview(titleLabel)
titleLabel.snp.makeConstraints { (make) in
make.centerX.equalToSuperview()
make.top.equalTo(valueLabel.snp.bottom).offset(14)
make.left.lessThanOrEqualToSuperview().inset(16)
make.right.lessThanOrEqualToSuperview().inset(16)
make.bottom.equalToSuperview().inset(19)
}
}
}
class CurrentForecastDetailsCell: UITableViewCell {
//Public
static let kIdentifier = "currentForecastDetailsCell"
//Private
private let detailsLabel = UILabel()
private let scrollView = UIScrollView()
private let stackView = UIStackView()
private let progressView = UIView()
private let progressIndicator = UIView()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
prepareCell()
preareLabel()
prepareScrollView()
prepareStackView()
prepareProgressIndicator()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//MARK:- Prepare
private extension CurrentForecastDetailsCell {
func prepareCell() {
contentView.backgroundColor = .clear
backgroundColor = .clear
}
func preareLabel() {
detailsLabel.text = "Details"
detailsLabel.font = UIFont.boldSystemFont(ofSize: 18)
detailsLabel.textColor = .white
contentView.addSubview(detailsLabel)
detailsLabel.snp.makeConstraints { (make) in
make.left.equalToSuperview().inset(16)
make.top.equalToSuperview().inset(8)
}
}
func prepareScrollView() {
scrollView.backgroundColor = .clear
scrollView.contentInset = .init(top: 0, left: 16, bottom: 0, right: 16)
scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false
contentView.addSubview(scrollView)
scrollView.snp.makeConstraints { (make) in
make.top.equalTo(detailsLabel.snp.bottom).offset(14)
make.left.equalToSuperview()
make.right.equalToSuperview()
make.height.equalTo(85)
}
}
func prepareStackView() {
let backgroundContainer = UIView()
backgroundContainer.layer.cornerRadius = 4
backgroundContainer.clipsToBounds = true
backgroundContainer.backgroundColor = UIColor.black.withAlphaComponent(0.4)
scrollView.addSubview(backgroundContainer)
backgroundContainer.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
stackView.axis = .horizontal
stackView.distribution = .equalSpacing
stackView.alignment = .center
stackView.spacing = 8
stackView.clipsToBounds = true
backgroundContainer.addSubview(stackView)
stackView.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
make.height.equalTo(scrollView)
}
//Cards
for index in 0...5 {
let cardView:InfoCardView
switch index {
case 0:
cardView = InfoCardView(title: "Precipitation", value: "0%")
case 1:
cardView = InfoCardView(title: "Humidity", value: "0%")
case 2:
cardView = InfoCardView(title: "Wind", value: "0%")
case 3:
cardView = InfoCardView(title: "Pressure", value: "0%")
case 4:
cardView = InfoCardView(title: "UV", value: "0")
case 5:
cardView = InfoCardView(title: "Visible", value: "19")
default:
cardView = InfoCardView(title: "Error", value: "")
}
stackView.addArrangedSubview(cardView)
//Add separators
if index < 5 {
let separator = UIView()
separator.backgroundColor = UIColor.white.withAlphaComponent(0.3)
stackView.addArrangedSubview(separator)
separator.snp.makeConstraints { (make) in
make.size.equalTo(CGSize(width: 1, height: 42))
}
}
}
}
func prepareProgressIndicator() {
progressView.backgroundColor = UIColor.white.withAlphaComponent(0.3)
progressView.layer.cornerRadius = 2
progressView.clipsToBounds = true
contentView.addSubview(progressView)
progressView.snp.makeConstraints { (make) in
make.top.equalTo(scrollView.snp.bottom).offset(12)
make.centerX.equalToSuperview()
make.width.equalTo(68)
make.height.equalTo(4)
make.bottom.equalToSuperview().inset(8)
}
progressIndicator.backgroundColor = UIColor(hex: 0xFFD622)
progressIndicator.layer.cornerRadius = 2
progressIndicator.clipsToBounds = true
progressView.addSubview(progressIndicator)
progressIndicator.snp.makeConstraints { (make) in
make.height.equalToSuperview()
make.left.equalToSuperview()
make.centerY.equalToSuperview()
make.width.equalTo(16)
}
}
}
......@@ -21,6 +21,7 @@ class ViewController: UIViewController {
private extension ViewController {
func prepareTableView() {
tableView.register(CurrentForecastCell.self, forCellReuseIdentifier: CurrentForecastCell.kIdentifier)
tableView.register(CurrentForecastDetailsCell.self, forCellReuseIdentifier: CurrentForecastDetailsCell.kIdentifier)
tableView.estimatedRowHeight = 160
tableView.backgroundColor = .clear
tableView.rowHeight = UITableView.automaticDimension
......@@ -36,12 +37,19 @@ private extension ViewController {
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
return 2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: CurrentForecastCell.kIdentifier, for: indexPath) as! CurrentForecastCell
return cell
switch indexPath.row {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: CurrentForecastCell.kIdentifier, for: indexPath)
return cell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: CurrentForecastDetailsCell.kIdentifier, for: indexPath)
return cell
default:
return UITableViewCell()
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment