Commit d35e906a by Dmitriy Stepanets

Working on legend view animation/layout

parent 38c8f007
No preview for this file type
...@@ -128,6 +128,8 @@ ...@@ -128,6 +128,8 @@
CDD0F1E82572429E00CF5017 /* AppFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD0F1E72572429E00CF5017 /* AppFont.swift */; }; CDD0F1E82572429E00CF5017 /* AppFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD0F1E72572429E00CF5017 /* AppFont.swift */; };
CDD0F1EE25725BCF00CF5017 /* ThemeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD0F1ED25725BCF00CF5017 /* ThemeManager.swift */; }; CDD0F1EE25725BCF00CF5017 /* ThemeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD0F1ED25725BCF00CF5017 /* ThemeManager.swift */; };
CDD75F0D25DE68B10099ACDB /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = CDD75F0F25DE68B10099ACDB /* Localizable.strings */; }; CDD75F0D25DE68B10099ACDB /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = CDD75F0F25DE68B10099ACDB /* Localizable.strings */; };
CDDE8D7C262EED3C00267931 /* MapLegendSevereView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDDE8D7B262EED3C00267931 /* MapLegendSevereView.swift */; };
CDDE8D7F262EED4D00267931 /* MapLegendWeatherView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDDE8D7E262EED4D00267931 /* MapLegendWeatherView.swift */; };
CDE18DCA25D165F100C80ED9 /* UITabBarController+Append.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DC925D165F100C80ED9 /* UITabBarController+Append.swift */; }; CDE18DCA25D165F100C80ED9 /* UITabBarController+Append.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DC925D165F100C80ED9 /* UITabBarController+Append.swift */; };
CDE18DCD25D1666700C80ED9 /* ForecastCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DCC25D1666700C80ED9 /* ForecastCoordinator.swift */; }; CDE18DCD25D1666700C80ED9 /* ForecastCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DCC25D1666700C80ED9 /* ForecastCoordinator.swift */; };
CDE18DD125D166F900C80ED9 /* ForecastViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */; }; CDE18DD125D166F900C80ED9 /* ForecastViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */; };
...@@ -333,6 +335,8 @@ ...@@ -333,6 +335,8 @@
CDD0F1E72572429E00CF5017 /* AppFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppFont.swift; sourceTree = "<group>"; }; CDD0F1E72572429E00CF5017 /* AppFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppFont.swift; sourceTree = "<group>"; };
CDD0F1ED25725BCF00CF5017 /* ThemeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeManager.swift; sourceTree = "<group>"; }; CDD0F1ED25725BCF00CF5017 /* ThemeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeManager.swift; sourceTree = "<group>"; };
CDD75F0E25DE68B10099ACDB /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; }; CDD75F0E25DE68B10099ACDB /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
CDDE8D7B262EED3C00267931 /* MapLegendSevereView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapLegendSevereView.swift; sourceTree = "<group>"; };
CDDE8D7E262EED4D00267931 /* MapLegendWeatherView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapLegendWeatherView.swift; sourceTree = "<group>"; };
CDE18DC925D165F100C80ED9 /* UITabBarController+Append.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITabBarController+Append.swift"; sourceTree = "<group>"; }; CDE18DC925D165F100C80ED9 /* UITabBarController+Append.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITabBarController+Append.swift"; sourceTree = "<group>"; };
CDE18DCC25D1666700C80ED9 /* ForecastCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastCoordinator.swift; sourceTree = "<group>"; }; CDE18DCC25D1666700C80ED9 /* ForecastCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastCoordinator.swift; sourceTree = "<group>"; };
CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastViewController.swift; sourceTree = "<group>"; }; CDE18DD025D166F900C80ED9 /* ForecastViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastViewController.swift; sourceTree = "<group>"; };
...@@ -796,6 +800,8 @@ ...@@ -796,6 +800,8 @@
CDAD97B0262042B2007FCFB1 /* MapButton.swift */, CDAD97B0262042B2007FCFB1 /* MapButton.swift */,
CD18728A2624763000AFEDAA /* MapLegendView.swift */, CD18728A2624763000AFEDAA /* MapLegendView.swift */,
CD676169262575CD0079D273 /* MapLegendGradientView.swift */, CD676169262575CD0079D273 /* MapLegendGradientView.swift */,
CDDE8D7B262EED3C00267931 /* MapLegendSevereView.swift */,
CDDE8D7E262EED4D00267931 /* MapLegendWeatherView.swift */,
); );
path = Controls; path = Controls;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1293,6 +1299,7 @@ ...@@ -1293,6 +1299,7 @@
CD866A62260F596B00E96A5C /* Dimension+Name.swift in Sources */, CD866A62260F596B00E96A5C /* Dimension+Name.swift in Sources */,
CDE2BF222609D4250085C930 /* ForecastWindSpeedCell.swift in Sources */, CDE2BF222609D4250085C930 /* ForecastWindSpeedCell.swift in Sources */,
CD866A6C260F676400E96A5C /* SettingsDetailsCellFactory.swift in Sources */, CD866A6C260F676400E96A5C /* SettingsDetailsCellFactory.swift in Sources */,
CDDE8D7F262EED4D00267931 /* MapLegendWeatherView.swift in Sources */,
CDA5543025EFA13F00A2E08C /* Measurement+String.swift in Sources */, CDA5543025EFA13F00A2E08C /* Measurement+String.swift in Sources */,
CEF9596C2600C32E00975FAA /* AnalyticsEvent.swift in Sources */, CEF9596C2600C32E00975FAA /* AnalyticsEvent.swift in Sources */,
CEF959982600C88100975FAA /* AnalyticsParameter.swift in Sources */, CEF959982600C88100975FAA /* AnalyticsParameter.swift in Sources */,
...@@ -1427,6 +1434,7 @@ ...@@ -1427,6 +1434,7 @@
CD86246125E662BC0097F3FB /* SunUvLineView.swift in Sources */, CD86246125E662BC0097F3FB /* SunUvLineView.swift in Sources */,
CD32CE0B260C744A00235081 /* MenuCoordinator.swift in Sources */, CD32CE0B260C744A00235081 /* MenuCoordinator.swift in Sources */,
CD55E0BB2615EE2400CC4DC7 /* PollutantView.swift in Sources */, CD55E0BB2615EE2400CC4DC7 /* PollutantView.swift in Sources */,
CDDE8D7C262EED3C00267931 /* MapLegendSevereView.swift in Sources */,
CD6761882625C3360079D273 /* RadarViewModel.swift in Sources */, CD6761882625C3360079D273 /* RadarViewModel.swift in Sources */,
CDF8F12A262089A200DB384A /* MapTimeView.swift in Sources */, CDF8F12A262089A200DB384A /* MapTimeView.swift in Sources */,
CEC526FA25E7959A00DA58A5 /* WeatherSource.swift in Sources */, CEC526FA25E7959A00DA58A5 /* WeatherSource.swift in Sources */,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<key>1Weather.xcscheme_^#shared#^_</key> <key>1Weather.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>11</integer> <integer>24</integer>
</dict> </dict>
<key>PG (Playground) 1.xcscheme</key> <key>PG (Playground) 1.xcscheme</key>
<dict> <dict>
......
...@@ -33,29 +33,86 @@ public enum SevereLayerType:String, CaseIterable, RadarLayerType { ...@@ -33,29 +33,86 @@ public enum SevereLayerType:String, CaseIterable, RadarLayerType {
case .fire: case .fire:
return ["Watch", "Warning"] return ["Watch", "Warning"]
case .floods: case .floods:
return ["Flash warn.", "Flash watch", "Flood warn."] return ["Flash warning", "Flash watch", "Flood warning"]
case .fog: case .fog:
return ["Freezing adv." , "Dense adv."] return ["Freezing advisory" , "Dense advisory"]
case .freezing: case .freezing:
return ["Freezing warn.", "Frost adv.", "Frost warn."] return ["Freezing warning", "Frost advisory", "Frost warning"]
case .hurricaneTropical: case .hurricaneTropical:
return ["Warning", "Watch", "Tropical warn.", "Tropical watch"] return ["Warning", "Watch", "Tropical warning", "Tropical watch"]
case .hurricaneTropicalTracks: case .hurricaneTropicalTracks:
return ["Forecast track", "Past track", "Forecast cone", "Hurricane", "Tropical storm", "Low", "Invest area"] return ["Forecast track", "Past track", "Forecast cone", "Hurricane", "Tropical storm", "Low", "Invest area"]
case .ice: case .ice:
return ["Strom warn.", "Storm watch", "Sleet warn.", "Sleet adv.", "Freezing rain adv."] return ["Strom warning", "Storm watch", "Sleet warning", "Sleet advisory", "Freezing rain adisory."]
case .snow: case .snow:
return ["Heavy snow warn.", "Snow adv.", "Blowing snow warn.", "Blowing snow adv."] return ["Heavy snow warning", "Snow advisory", "Blowing snow warning", "Blowing snow advisory"]
case .stormTornados: case .stormTornados:
return ["Tornado warn.", "Tornado watch", "Severe T-Storm warn.", "Severe T-storm watch"] return ["Tornado warning", "Tornado watch", "Severe T-Storm warning", "Severe T-storm watch"]
case .wind: case .wind:
return ["High wind warn.", "High wind adv.", "High wind watch", "Wind adv.", "Dust strom warn.", "Blowing dust adv."] return ["High wind warning", "High wind advisory", "High wind watch", "Wind advisory", "Dust strom warning", "Blowing dust advisory"]
case .winter: case .winter:
return ["Blizzard warn.", "Blizzard watch", "Winter strom warn.", "Winter storm watch", "Winter weather adv."] return ["Blizzard warning", "Blizzard watch", "Winter strom warning", "Winter storm watch", "Winter weather advisory"]
} }
} }
var colors:[CGColor] { var colors:[CGColor] {
return [UIColor.blue, UIColor.yellow].map{$0.cgColor} switch self {
case .fire:
return [UIColor(hex: 0xFFDDAD),
UIColor(hex: 0xFF1494)].map{$0.cgColor}
case .floods:
return [UIColor(hex: 0x8C0001),
UIColor(hex: 0x32CD33),
UIColor(hex: 0x00FF01)].map{$0.cgColor}
case .fog:
return [UIColor(hex: 0x008081),
UIColor(hex: 0x708090)].map{$0.cgColor}
case .freezing:
return [UIColor(hex: 0x00FFFF),
UIColor(hex: 0x6395EC),
UIColor(hex: 0x2B32B4)].map{$0.cgColor}
case .hurricaneTropical:
return [UIColor(hex: 0xFE1745),
UIColor(hex: 0xFF00FE),
UIColor(hex: 0x7F1819),
UIColor(hex: 0xF0807F)].map{$0.cgColor}
case .hurricaneTropicalTracks:
return [UIColor.black,
UIColor.black,
UIColor.black,
UIColor.black,
UIColor.black,
UIColor.black,
UIColor.black].map{$0.cgColor}
case .ice:
return [UIColor(hex: 0x8A008B),
UIColor(hex: 0x8A008B),
UIColor(hex: 0x87CEEA),
UIColor(hex: 0x7C68EE),
UIColor(hex: 0xDA70D5)].map{$0.cgColor}
case .snow:
return [UIColor(hex: 0x8A2BE1),
UIColor(hex: 0x669ACC),
UIColor(hex: 0xB0DFE5),
UIColor(hex: 0x81A1AC)].map{$0.cgColor}
case .stormTornados:
return [UIColor(hex: 0xFE0000),
UIColor(hex: 0xFFFF01),
UIColor(hex: 0xFEA500),
UIColor(hex: 0xDC7092)].map{$0.cgColor}
case .wind:
return [UIColor(hex: 0xDAA521),
UIColor(hex: 0xA78432),
UIColor(hex: 0xC48B00),
UIColor(hex: 0x9C8768),
UIColor(hex: 0xFEE4C3),
UIColor(hex: 0xAFAB64)].map{$0.cgColor}
case .winter:
return [UIColor(hex: 0xFE4600),
UIColor(hex: 0xCFFF86),
UIColor(hex: 0xFF69B3),
UIColor(hex: 0x4682B4),
UIColor(hex: 0x7C68EE)].map{$0.cgColor}
}
} }
} }
//
// MapLegendSevereView.swift
// 1Weather
//
// Created by Dmitry Stepanets on 20.04.2021.
//
import UIKit
class MapLegendSevereView: UIView {
//Private
private let stackView = UIStackView()
init() {
super.init(frame: .zero)
prepare()
}
public func configure(severeLayer:SevereLayerType) {
stackView.removeAll()
severeLayer.values.enumerated().forEach {
let element = SevereLegendElement(color:UIColor(cgColor: severeLayer.colors[$0]), value: $1)
stackView.addArrangedSubview(element)
}
stackView.layoutIfNeeded()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func prepare() {
stackView.axis = .horizontal
stackView.spacing = 4
stackView.distribution = .equalSpacing
addSubview(stackView)
stackView.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
}
}
//MARK:- Severe Legend Element
private class SevereLegendElement:UIView {
private let imageView = UIImageView()
private let textLabel = UILabel()
init(color:UIColor, value:String) {
super.init(frame: .zero)
prepare()
updateUI()
imageView.backgroundColor = color
textLabel.text = value
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
updateUI()
}
private func prepare() {
self.snp.makeConstraints { (make) in
make.width.equalTo(50)
}
imageView.clipsToBounds = true
imageView.layer.cornerRadius = 5
imageView.contentMode = .scaleAspectFit
addSubview(imageView)
imageView.snp.makeConstraints { (make) in
make.top.equalToSuperview().inset(3)
make.width.equalTo(30)
make.height.equalTo(10)
make.centerX.equalToSuperview()
}
textLabel.font = AppFont.SFPro.medium(size: 10)
textLabel.numberOfLines = 0
textLabel.textAlignment = .center
textLabel.lineBreakMode = .byWordWrapping
addSubview(textLabel)
textLabel.snp.makeConstraints { (make) in
make.left.right.equalToSuperview()
make.top.equalTo(imageView.snp.bottom).offset(2)
make.bottom.equalToSuperview().inset(2)
}
}
private func updateUI() {
switch interfaceStyle {
case .light:
textLabel.textColor = ThemeManager.currentTheme.secondaryTextColor
case .dark:
textLabel.textColor = ThemeManager.currentTheme.primaryTextColor
}
}
}
...@@ -8,16 +8,24 @@ ...@@ -8,16 +8,24 @@
import UIKit import UIKit
import SnapKit import SnapKit
private enum LegendType {
case weather
case severe
}
class MapLegendView: UIView { class MapLegendView: UIView {
//Private //Private
private let kOpenWidth:CGFloat = 180 private let kOpenWidth:CGFloat = 180
private let kCloseWidth:CGFloat = 40 private let kCloseWidth:CGFloat = 40
private let containerView = UIView()
private let button = UIButton() private let button = UIButton()
private let viewGradient = CAGradientLayer() private let viewGradient = CAGradientLayer()
private let buttonGradient = CAGradientLayer() private let buttonGradient = CAGradientLayer()
private let legendGradient = MapLegendGradientView() private let legendWeatherView = MapLegendWeatherView()
private let legendLabelsStackView = UIStackView() private let legendSevereView = MapLegendSevereView()
private var legendLabels = [UILabel]() private var legendType = LegendType.weather
private var widthConstraint:Constraint?
private var heightConstraint:Constraint?
private var isOpened = false private var isOpened = false
init() { init() {
...@@ -49,21 +57,33 @@ class MapLegendView: UIView { ...@@ -49,21 +57,33 @@ class MapLegendView: UIView {
//Public //Public
public func configure(radarLayer:RadarLayer) { public func configure(radarLayer:RadarLayer) {
legendGradient.set(colors: radarLayer.layer.colors) legendSevereView.alpha = 0
buttonGradient.colors = radarLayer.layer.colors legendWeatherView.alpha = 0
if let weatherLayer = radarLayer.layer as? WeatherLayerType {
self.configure(weatherLayer: weatherLayer)
}
legendLabelsStackView.removeAll() if let severeLayer = radarLayer.layer as? SevereLayerType {
radarLayer.layer.values.enumerated().forEach { self.configure(severeLayer: severeLayer)
let label = UILabel()
label.font = AppFont.SFPro.regular(size: 10)
label.text = $1
self.legendLabels.append(label)
legendLabelsStackView.addArrangedSubview(label)
} }
legendLabelsStackView.layoutIfNeeded()
} }
//Private //Private
private func configure(weatherLayer:WeatherLayerType) {
legendType = .weather
legendWeatherView.alpha = isOpened ? 1 : 0
buttonGradient.colors = weatherLayer.colors
legendWeatherView.configure(weatherLayer: weatherLayer)
}
private func configure(severeLayer:SevereLayerType) {
legendType = .severe
legendSevereView.alpha = isOpened ? 1 : 0
buttonGradient.colors = severeLayer.colors
legendSevereView.configure(severeLayer: severeLayer)
}
private func updateUI() { private func updateUI() {
switch interfaceStyle { switch interfaceStyle {
case .light: case .light:
...@@ -78,23 +98,25 @@ class MapLegendView: UIView { ...@@ -78,23 +98,25 @@ class MapLegendView: UIView {
@objc private func handleButton() { @objc private func handleButton() {
if self.isOpened { if self.isOpened {
self.isOpened = false self.isOpened = false
self.snp.updateConstraints { (update) in self.widthConstraint?.isActive = true
update.width.equalTo(self.kCloseWidth) self.heightConstraint?.isActive = true
}
} }
else { else {
self.isOpened = true self.isOpened = true
self.snp.updateConstraints { (update) in self.widthConstraint?.isActive = false
update.width.equalTo(self.kOpenWidth) self.heightConstraint?.isActive = false
}
} }
self.setNeedsLayout() self.setNeedsLayout()
self.button.setImage(isOpened ? UIImage(named: "map_legend_close") : nil, for: .normal) self.button.setImage(isOpened ? UIImage(named: "map_legend_close") : nil, for: .normal)
UIView.animate(withDuration: 0.3) { UIView.animate(withDuration: 0.3) {
self.superview?.layoutIfNeeded() self.superview?.layoutIfNeeded()
self.legendGradient.alpha = self.isOpened ? 1 : 0 switch self.legendType {
self.legendLabelsStackView.alpha = self.isOpened ? 1 : 0 case .weather:
self.legendWeatherView.alpha = self.isOpened ? 1 : 0
case .severe:
self.legendSevereView.alpha = self.isOpened ? 1 : 0
}
self.layer.borderWidth = self.isOpened ? 0.5 : 0 self.layer.borderWidth = self.isOpened ? 0.5 : 0
} }
} }
...@@ -110,8 +132,10 @@ private extension MapLegendView { ...@@ -110,8 +132,10 @@ private extension MapLegendView {
layer.shadowOpacity = 1 layer.shadowOpacity = 1
layer.shadowRadius = 5 layer.shadowRadius = 5
self.snp.makeConstraints { (make) in addSubview(containerView)
make.width.height.equalTo(40).priority(1000) containerView.snp.makeConstraints { (make) in
make.left.top.bottom.equalToSuperview()
self.widthConstraint = make.width.equalTo(kCloseWidth).priority(1000).constraint
} }
} }
...@@ -130,7 +154,7 @@ private extension MapLegendView { ...@@ -130,7 +154,7 @@ private extension MapLegendView {
button.layer.cornerRadius = 14 button.layer.cornerRadius = 14
button.addTarget(self, action: #selector(handleButton), for: .touchUpInside) button.addTarget(self, action: #selector(handleButton), for: .touchUpInside)
button.layer.insertSublayer(buttonGradient, below: button.imageView?.layer) button.layer.insertSublayer(buttonGradient, below: button.imageView?.layer)
addSubview(button) containerView.addSubview(button)
button.snp.makeConstraints { (make) in button.snp.makeConstraints { (make) in
make.width.height.equalTo(28) make.width.height.equalTo(28)
...@@ -140,26 +164,23 @@ private extension MapLegendView { ...@@ -140,26 +164,23 @@ private extension MapLegendView {
} }
func prepareLegend() { func prepareLegend() {
legendGradient.alpha = 0 legendWeatherView.alpha = 0
legendGradient.layer.cornerRadius = 2 containerView.addSubview(legendWeatherView)
addSubview(legendGradient)
legendGradient.snp.makeConstraints { (make) in legendWeatherView.snp.makeConstraints { (make) in
make.left.equalTo(button.snp.right).offset(6).priority(999) make.left.equalTo(button.snp.right).offset(6).priority(999)
make.top.equalToSuperview().inset(13)
make.height.equalTo(4)
make.right.equalToSuperview().inset(17) make.right.equalToSuperview().inset(17)
make.top.equalToSuperview().inset(13)
make.bottom.equalToSuperview().inset(6)
} }
//Labels legendSevereView.alpha = 0
legendLabelsStackView.alpha = 0 containerView.addSubview(legendSevereView)
legendLabelsStackView.axis = .horizontal
legendLabelsStackView.distribution = .equalCentering
addSubview(legendLabelsStackView)
legendLabelsStackView.snp.makeConstraints { (make) in legendSevereView.snp.makeConstraints { (make) in
make.left.right.equalTo(legendGradient) make.left.equalTo(button.snp.right).offset(6).priority(999)
make.top.equalTo(legendGradient.snp.bottom).offset(6) make.right.equalToSuperview().inset(17)
make.top.bottom.equalToSuperview()
} }
} }
} }
//
// MapLegendWeatherView.swift
// 1Weather
//
// Created by Dmitry Stepanets on 20.04.2021.
//
import UIKit
class MapLegendWeatherView: UIView {
//Private
private let legendGradient = MapLegendGradientView()
private let legendLabelsStackView = UIStackView()
private var legendLabels = [UILabel]()
override init(frame: CGRect) {
super.init(frame: frame)
prepareLegend()
prepareStackView()
updateUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
updateUI()
}
public func configure(weatherLayer:WeatherLayerType) {
legendGradient.set(colors: weatherLayer.colors)
legendLabelsStackView.removeAll()
weatherLayer.values.enumerated().forEach {
let label = UILabel()
label.font = AppFont.SFPro.regular(size: 10)
label.text = $1
self.legendLabels.append(label)
legendLabelsStackView.addArrangedSubview(label)
}
legendLabelsStackView.layoutIfNeeded()
}
//Private
private func updateUI() {
self.legendLabels.forEach {
switch interfaceStyle {
case .light:
$0.textColor = ThemeManager.currentTheme.secondaryTextColor
case .dark:
$0.textColor = ThemeManager.currentTheme.primaryTextColor
}
}
}
}
private extension MapLegendWeatherView {
func prepareLegend() {
legendGradient.layer.cornerRadius = 2
addSubview(legendGradient)
legendGradient.snp.makeConstraints { (make) in
make.left.right.top.equalToSuperview()
make.height.equalTo(4)
}
}
func prepareStackView() {
legendLabelsStackView.axis = .horizontal
legendLabelsStackView.spacing = 4
legendLabelsStackView.distribution = .equalSpacing
addSubview(legendLabelsStackView)
legendLabelsStackView.snp.makeConstraints { (make) in
make.left.right.equalToSuperview()
make.top.equalTo(legendGradient.snp.bottom).offset(6)
make.bottom.equalToSuperview().inset(4)
}
}
}
...@@ -21,14 +21,14 @@ ...@@ -21,14 +21,14 @@
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>0</integer> <integer>1</integer>
</dict> </dict>
<key>Cirque.xcscheme</key> <key>Cirque.xcscheme</key>
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>3</integer> <integer>4</integer>
</dict> </dict>
<key>Cirque.xcscheme_^#shared#^_</key> <key>Cirque.xcscheme_^#shared#^_</key>
<dict> <dict>
...@@ -232,7 +232,7 @@ ...@@ -232,7 +232,7 @@
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>1</integer> <integer>2</integer>
</dict> </dict>
<key>PromisesObjC.xcscheme</key> <key>PromisesObjC.xcscheme</key>
<dict> <dict>
...@@ -251,7 +251,7 @@ ...@@ -251,7 +251,7 @@
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>2</integer> <integer>3</integer>
</dict> </dict>
<key>XMLCoder.xcscheme</key> <key>XMLCoder.xcscheme</key>
<dict> <dict>
......
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