diff --git a/assignment1/assignment1/Applications/SceneDelegate.swift b/assignment1/assignment1/Applications/SceneDelegate.swift index 2fb2b3a..6b8481b 100644 --- a/assignment1/assignment1/Applications/SceneDelegate.swift +++ b/assignment1/assignment1/Applications/SceneDelegate.swift @@ -18,7 +18,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { guard let windowScene = (scene as? UIWindowScene) else { return } let window = UIWindow(windowScene: windowScene) - window.rootViewController = UINavigationController(rootViewController: WheatherListViewController()) + window.rootViewController = UINavigationController(rootViewController: WeatherListViewController()) window.makeKeyAndVisible() self.window = window } diff --git a/assignment1/assignment1/Global/Protocols/Protocol.swift b/assignment1/assignment1/Global/Protocols/Protocol.swift index 33e9091..c804222 100644 --- a/assignment1/assignment1/Global/Protocols/Protocol.swift +++ b/assignment1/assignment1/Global/Protocols/Protocol.swift @@ -9,10 +9,7 @@ import Foundation -protocol WeatherInfoViewDelegate: AnyObject { - func weatherInfoViewTapped(_ cityListView: CityListView) -} -protocol BottomAppBarDelegate: AnyObject { - func listButtonPressed(_ BottomAppBar: BottomAppBar) -} +//protocol BottomAppBarDelegate: AnyObject { +// func listButtonPressed(_ BottomAppBar: BottomAppBar) +//} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/calendar.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/calendar.imageset/Contents.json new file mode 100644 index 0000000..4d62994 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/calendar.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 14.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/calendar.imageset/Frame 14.png b/assignment1/assignment1/Global/Resources/Assets.xcassets/calendar.imageset/Frame 14.png new file mode 100644 index 0000000..f3cc98b Binary files /dev/null and b/assignment1/assignment1/Global/Resources/Assets.xcassets/calendar.imageset/Frame 14.png differ diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar1.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar1.imageset/Contents.json new file mode 100644 index 0000000..cb8f300 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar1.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 17.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar1.imageset/Frame 17.svg b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar1.imageset/Frame 17.svg new file mode 100644 index 0000000..920d55d --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar1.imageset/Frame 17.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar10.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar10.imageset/Contents.json new file mode 100644 index 0000000..146f69d --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar10.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 26.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar10.imageset/Frame 26.svg b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar10.imageset/Frame 26.svg new file mode 100644 index 0000000..ef5daf8 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar10.imageset/Frame 26.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar11.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar11.imageset/Contents.json new file mode 100644 index 0000000..42c76db --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar11.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 27.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar11.imageset/Frame 27.svg b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar11.imageset/Frame 27.svg new file mode 100644 index 0000000..4e1cc23 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar11.imageset/Frame 27.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar2.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar2.imageset/Contents.json new file mode 100644 index 0000000..551b0ea --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar2.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 19.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar2.imageset/Frame 19.svg b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar2.imageset/Frame 19.svg new file mode 100644 index 0000000..acab4d0 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar2.imageset/Frame 19.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar3.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar3.imageset/Contents.json new file mode 100644 index 0000000..34ddbc0 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar3.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 20.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar3.imageset/Frame 20.svg b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar3.imageset/Frame 20.svg new file mode 100644 index 0000000..11cb4e8 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar3.imageset/Frame 20.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar4.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar4.imageset/Contents.json new file mode 100644 index 0000000..c90de06 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar4.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 18.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar4.imageset/Frame 18.svg b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar4.imageset/Frame 18.svg new file mode 100644 index 0000000..d23c9d5 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar4.imageset/Frame 18.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar5.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar5.imageset/Contents.json new file mode 100644 index 0000000..4bc828e --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar5.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 21.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar5.imageset/Frame 21.svg b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar5.imageset/Frame 21.svg new file mode 100644 index 0000000..e2e4e61 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar5.imageset/Frame 21.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar6.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar6.imageset/Contents.json new file mode 100644 index 0000000..ceae429 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar6.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 22.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar6.imageset/Frame 22.svg b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar6.imageset/Frame 22.svg new file mode 100644 index 0000000..36ee01c --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar6.imageset/Frame 22.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar7.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar7.imageset/Contents.json new file mode 100644 index 0000000..56b252d --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar7.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 23.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar7.imageset/Frame 23.svg b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar7.imageset/Frame 23.svg new file mode 100644 index 0000000..4287887 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar7.imageset/Frame 23.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar8.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar8.imageset/Contents.json new file mode 100644 index 0000000..699b351 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar8.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 24.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar8.imageset/Frame 24.svg b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar8.imageset/Frame 24.svg new file mode 100644 index 0000000..a992c7c --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar8.imageset/Frame 24.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar9.imageset/Contents.json b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar9.imageset/Contents.json new file mode 100644 index 0000000..027f007 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar9.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Frame 25.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar9.imageset/Frame 25.svg b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar9.imageset/Frame 25.svg new file mode 100644 index 0000000..90a3691 --- /dev/null +++ b/assignment1/assignment1/Global/Resources/Assets.xcassets/tempBar9.imageset/Frame 25.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/assignment1/assignment1/Global/Resources/Fonts/SF-Pro-Display-Light.otf b/assignment1/assignment1/Global/Resources/Fonts/SF-Pro-Display-Light.otf new file mode 100755 index 0000000..1a3f4d4 Binary files /dev/null and b/assignment1/assignment1/Global/Resources/Fonts/SF-Pro-Display-Light.otf differ diff --git a/assignment1/assignment1/Global/Resources/Info.plist b/assignment1/assignment1/Global/Resources/Info.plist index a489205..458530c 100644 --- a/assignment1/assignment1/Global/Resources/Info.plist +++ b/assignment1/assignment1/Global/Resources/Info.plist @@ -4,6 +4,7 @@ UIAppFonts + SF-Pro-Display-Light.otf SF-Pro-Display-Bold.otf SF-Pro-Display-Thin.otf SF-Pro-Text-Semibold.otf diff --git a/assignment1/assignment1/Info.plist b/assignment1/assignment1/Info.plist index 526de9c..690679c 100644 --- a/assignment1/assignment1/Info.plist +++ b/assignment1/assignment1/Info.plist @@ -4,7 +4,11 @@ UIAppFonts + SF-Pro-Display-Thin.otf SF-Pro-Display-Regular.otf + SF-Pro.otf + SF-Pro-Display-Bold.otf + SF-Pro-Display-Light.otf UIApplicationSceneManifest diff --git a/assignment1/assignment1/Presentations/WeatherDetail/Views/BottomAppBar.swift b/assignment1/assignment1/Presentations/WeatherDetail/Main/BottomAppBar.swift similarity index 75% rename from assignment1/assignment1/Presentations/WeatherDetail/Views/BottomAppBar.swift rename to assignment1/assignment1/Presentations/WeatherDetail/Main/BottomAppBar.swift index 8349869..1cbd9e8 100644 --- a/assignment1/assignment1/Presentations/WeatherDetail/Views/BottomAppBar.swift +++ b/assignment1/assignment1/Presentations/WeatherDetail/Main/BottomAppBar.swift @@ -8,19 +8,20 @@ import Foundation import UIKit +import SnapKit +import Then class BottomAppBar: UIView { - weak var delegate: BottomAppBarDelegate? + // weak var delegate: BottomAppBarDelegate? private let lineView = UIView() private let mapButton = UIButton() private let pageControl = UIPageControl() - let listButton: UIButton = { - let button = UIButton() - button.setImage(UIImage(named: "menuIcon"), for: .normal) - return button - } () + var listButton = UIButton().then { + $0.setImage(UIImage(named: "menuIcon"), for: .normal) + $0.addTarget(self, action: #selector(WeatherDetailViewController.listButtonTapped), for: .touchUpInside) + } init() { super.init(frame: .zero) @@ -77,4 +78,15 @@ class BottomAppBar: UIView { } } + +} + +extension WeatherDetailViewController { + @objc func listButtonTapped() { + // listButton이 눌렸을 때 실행할 코드를 작성 + // 예를 들면 뷰 컨트롤러를 팝하거나 다른 화면으로 이동하는 등의 작업 + print("listButton이 눌렸습니다.") + self.navigationController?.isNavigationBarHidden = false + self.navigationController?.popViewController(animated: true) + } } diff --git a/assignment1/assignment1/Presentations/WeatherDetail/Main/WeatherDetailViewController.swift b/assignment1/assignment1/Presentations/WeatherDetail/Main/WeatherDetailViewController.swift new file mode 100644 index 0000000..ddb72bc --- /dev/null +++ b/assignment1/assignment1/Presentations/WeatherDetail/Main/WeatherDetailViewController.swift @@ -0,0 +1,271 @@ +// +// WeatherDetailViewController.swift +// assignment1 +// +// Created by Seonwoo Kim on 2023/11/07. +// + +import UIKit +import SnapKit +import Then + +class WeatherDetailViewController: UIViewController { + + private let verticalScrollView = UIScrollView().then { + $0.alwaysBounceVertical = true + $0.showsVerticalScrollIndicator = false + } + + private let backgroundImageView = UIImageView().then { + $0.contentMode = .scaleAspectFill + $0.image = UIImage(named: "background") + } + + private var cityLabel = UILabel().then { + $0.textColor = .white + $0.text = "인천광역시" + $0.font = UIFont(name: "SFProDisplay-Regular", size: 36) + $0.textAlignment = .center + } + + private var tempLabel = UILabel().then { + $0.textColor = .white + $0.text = "21°" + $0.font = UIFont(name: "SFProDisplay-Regular", size: 102) + $0.textAlignment = .center + } + + private var wheatherStatusLabel = UILabel().then { + $0.textColor = .white + $0.text = "흐림" + $0.font = UIFont(name: "SFProDisplay-Regular", size: 25) + $0.textAlignment = .center + } + + private var minTempLabel = UILabel().then { + $0.textColor = .white + $0.text = "최저:19°" + $0.font = UIFont(name: "SFProDisplay-Regular", size: 20) + } + + private var maxTempLabel = UILabel().then { + $0.textColor = .white + $0.text = "최고:29°" + $0.font = UIFont(name: "SFProDisplay-Regular", size: 20) + } + + private let descriptionView = UIView().then { + $0.backgroundColor = UIColor(red: 0.18, green: 0.20, blue: 0.25, alpha: 0.25) + $0.layer.borderColor = CGColor(red: 255, green: 255, blue: 255, alpha: 0.25) + $0.layer.borderWidth = 1 + $0.layer.cornerRadius = 10 + } + + private var wheatherDescriptionLabel = UILabel().then { + $0.textColor = .white + $0.text = "08:00~09:00에 강우 상태가, 18:00에 한때 흐린 상태가 예상됩니다." + $0.font = UIFont(name: "SFProDisplay-Regular", size: 18) + $0.numberOfLines = 2 + } + + private var lineView = UIView().then { + $0.backgroundColor = UIColor.white.withAlphaComponent(0.3) + } + + private let horizontalCollectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()).then { + $0.backgroundColor = UIColor(red: 0.18, green: 0.20, blue: 0.25, alpha: 0.25) + } + + private var bottomBar = BottomAppBar() + + private let tenDaysWeatherView = UIView().then { + $0.backgroundColor = UIColor(red: 0.18, green: 0.20, blue: 0.25, alpha: 0.25) + $0.layer.borderColor = CGColor(red: 255, green: 255, blue: 255, alpha: 0.25) + $0.layer.borderWidth = 1 + $0.layer.cornerRadius = 10 + } + private let tenDaysImage = UIImageView().then { + $0.image = UIImage(systemName: "calendar") + $0.tintColor = UIColor(white: 1, alpha: 0.3) + } + private let tenDaysWeatherLabel = UILabel().then { + $0.text = "10일간의 일기예보" + $0.textColor = .white.withAlphaComponent(0.3) + $0.font = UIFont(name: "SFProDisplay-Regular", size: 15) + } + private let tenDaysWeatherTableView = UITableView(frame: .zero, style: .plain).then { + $0.backgroundColor = UIColor(red: 0.18, green: 0.20, blue: 0.25, alpha: 0.25) + $0.isScrollEnabled = false + $0.separatorStyle = .singleLine + $0.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + $0.separatorInsetReference = .fromAutomaticInsets + $0.separatorColor = .white + } + + override func viewDidLoad() { + super.viewDidLoad() + + setCollectionViewConfig() + setCollectionViewLayout() + setTableViewConfig() + setUpUI() + } +} + + +extension WeatherDetailViewController: UICollectionViewDelegate {} +extension WeatherDetailViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return weatherCollectionViewData.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + guard let item = collectionView.dequeueReusableCell(withReuseIdentifier: WeatherDetailCollectionViewCell.identifier, + for: indexPath) as? WeatherDetailCollectionViewCell else {return UICollectionViewCell()} + + item.bindData(data: weatherCollectionViewData[indexPath.row]) + return item + } +} + +extension WeatherDetailViewController { + private func setUpUI() { + + [backgroundImageView,bottomBar,verticalScrollView].forEach { + self.view.addSubview($0) + } + [tempLabel, cityLabel, wheatherStatusLabel, minTempLabel, maxTempLabel, descriptionView,tenDaysWeatherView].forEach { + self.verticalScrollView.addSubview($0) + } + [wheatherDescriptionLabel, lineView, horizontalCollectionView].forEach { + self.descriptionView.addSubview($0) + } + [tenDaysImage, + tenDaysWeatherLabel, + tenDaysWeatherTableView].forEach { + self.tenDaysWeatherView.addSubview($0) + } + + self.setLayout() + } + + private func setLayout() { + verticalScrollView.snp.makeConstraints { + $0.top.leading.trailing.equalToSuperview() + $0.bottom.equalTo(bottomBar.snp.top) + } + bottomBar.snp.makeConstraints { + $0.bottom.leading.trailing.equalToSuperview() + $0.height.equalTo(80) + } + backgroundImageView.snp.makeConstraints { + $0.edges.equalToSuperview() + } + + cityLabel.snp.makeConstraints { + $0.top.equalTo(verticalScrollView.snp.top).offset(50) + $0.centerX.equalToSuperview() + } + tempLabel.snp.makeConstraints { + $0.top.equalTo(cityLabel.snp.bottom).offset(5) + $0.centerX.equalToSuperview() + } + wheatherStatusLabel.snp.makeConstraints { + $0.top.equalTo(tempLabel.snp.bottom).offset(5) + $0.centerX.equalToSuperview() + } + minTempLabel.snp.makeConstraints { + $0.top.equalTo(wheatherStatusLabel.snp.bottom).offset(3) + $0.leading.equalTo(tempLabel.snp.leading) + } + maxTempLabel.snp.makeConstraints { + $0.top.equalTo(wheatherStatusLabel.snp.bottom).offset(3) + $0.trailing.equalTo(tempLabel.snp.trailing) + } + descriptionView.snp.makeConstraints { + $0.top.equalTo(maxTempLabel.snp.bottom).offset(50) + $0.centerX.equalToSuperview() + $0.height.equalTo(212) + $0.width.equalTo(335) + } + wheatherDescriptionLabel.snp.makeConstraints { + $0.top.equalTo(descriptionView.snp.top).offset(15) + $0.leading.equalTo(descriptionView.snp.leading).inset(10) + $0.trailing.equalTo(descriptionView.snp.trailing).inset(10) + } + lineView.snp.makeConstraints { + $0.top.equalTo(wheatherDescriptionLabel.snp.bottom).offset(20) + $0.leading.equalTo(descriptionView.snp.leading).inset(13) + $0.trailing.equalTo(descriptionView.snp.trailing).inset(13) + $0.height.equalTo(0.3) + } + horizontalCollectionView.snp.makeConstraints { + $0.top.equalTo(lineView.snp.bottom) + $0.bottom.equalTo(descriptionView.snp.bottom) + $0.leading.equalTo(descriptionView.snp.leading) + $0.trailing.equalTo(descriptionView.snp.trailing) + } + tenDaysWeatherView.snp.makeConstraints { + $0.top.equalTo(descriptionView.snp.bottom).offset(20) + $0.bottom.equalToSuperview().inset(86) + $0.height.equalTo(500) + $0.width.equalTo(335) + $0.centerX.equalToSuperview() + } + tenDaysImage.snp.makeConstraints { + $0.leading.equalToSuperview().inset(15) + $0.top.equalToSuperview().inset(10) + $0.size.equalTo(18) + } + tenDaysWeatherLabel.snp.makeConstraints { + $0.leading.equalTo(tenDaysImage.snp.trailing).offset(6) + $0.trailing.equalToSuperview().inset(15) + $0.top.equalToSuperview().inset(10) + } + tenDaysWeatherTableView.snp.makeConstraints { + $0.top.equalTo(tenDaysWeatherLabel.snp.bottom).offset(6) + $0.leading.trailing.bottom.equalToSuperview() + } + } + + private func setCollectionViewConfig() { + self.horizontalCollectionView.register(WeatherDetailCollectionViewCell.self, + forCellWithReuseIdentifier: WeatherDetailCollectionViewCell.identifier) + self.horizontalCollectionView.delegate = self + self.horizontalCollectionView.dataSource = self + } + + private func setTableViewConfig() { + self.tenDaysWeatherTableView.register(TenDaysTableViewCell.self, + forCellReuseIdentifier: TenDaysTableViewCell.identifier) + self.tenDaysWeatherTableView.delegate = self + self.tenDaysWeatherTableView.dataSource = self + } + + private func setCollectionViewLayout() { + let flowLayout = UICollectionViewFlowLayout() + flowLayout.itemSize = CGSize(width: 44 , height: 122) + flowLayout.scrollDirection = .horizontal + flowLayout.minimumLineSpacing = 22 + flowLayout.minimumInteritemSpacing = 3 + self.horizontalCollectionView.setCollectionViewLayout(flowLayout, animated: false) + } +} + +extension WeatherDetailViewController: UITableViewDelegate {} +extension WeatherDetailViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return tenDaysTableViewData.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + guard let cell = tableView.dequeueReusableCell(withIdentifier: TenDaysTableViewCell.identifier, + for: indexPath) as? TenDaysTableViewCell else {return UITableViewCell()} + + cell.bindData(data: tenDaysTableViewData[indexPath.row]) + cell.backgroundColor = .clear + cell.selectionStyle = .none + return cell + } + +} diff --git a/assignment1/assignment1/Presentations/WeatherDetail/TenDaysTableView/TenDaysTableViewCell.swift b/assignment1/assignment1/Presentations/WeatherDetail/TenDaysTableView/TenDaysTableViewCell.swift new file mode 100644 index 0000000..59d0fd7 --- /dev/null +++ b/assignment1/assignment1/Presentations/WeatherDetail/TenDaysTableView/TenDaysTableViewCell.swift @@ -0,0 +1,105 @@ +// +// TenDaysTableViewCell.swift +// assignment1 +// +// Created by Seonwoo Kim on 2023/11/08. +// + +import UIKit +import SnapKit +import Then + +class TenDaysTableViewCell: UITableViewCell { + static let identifier: String = "TenDaysTableViewCell" + + private let dateLabel = UILabel().then { + $0.textColor = .white + $0.font = UIFont(name: "SFProDisplay-Regular", size: 22) + } + + private let weatherImage = UIImageView() + + private let minTempLabel = UILabel().then { + $0.textColor = .white + $0.font = UIFont(name: "SFProDisplay-Regular", size: 22) + } + + private let degreeBarImage = UIImageView() + + private let maxTempLabel = UILabel().then { + $0.textColor = .white + $0.font = UIFont(name: "SFProDisplay-Regular", size: 22) + } + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + setUpUI() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setUpUI() { + [dateLabel,weatherImage,minTempLabel,maxTempLabel,degreeBarImage].forEach { + self.contentView.addSubview($0) + } + + self.setLayout() + } + + private func setLayout() { + dateLabel.snp.makeConstraints { + $0.centerY.equalToSuperview() + $0.top.equalToSuperview().inset(14) + $0.leading.equalToSuperview().inset(16) + $0.width.equalTo(45) + } + weatherImage.snp.makeConstraints { + $0.centerY.equalToSuperview() + $0.size.equalTo(28) + $0.leading.equalTo(dateLabel.snp.trailing).offset(30) + + } + minTempLabel.snp.makeConstraints { + $0.centerY.equalToSuperview() + $0.top.equalToSuperview().inset(14) + $0.leading.equalTo(weatherImage.snp.trailing).offset(15) + } + degreeBarImage.snp.makeConstraints { + $0.centerY.equalToSuperview() + $0.leading.equalTo(minTempLabel.snp.trailing).offset(6) + $0.width.equalTo(108) + } + maxTempLabel.snp.makeConstraints { + $0.centerY.equalToSuperview() + $0.top.equalToSuperview().inset(14) + $0.leading.equalTo(degreeBarImage.snp.trailing).offset(6) + } + } + + func bindData(data: TenDaysTableViewData) { + setWeatherImage(weather: data.weatherImage) + self.dateLabel.text = data.date + self.minTempLabel.text = data.minTemp + self.maxTempLabel.text = data.maxTemp + self.degreeBarImage.image = UIImage(named: data.degreeBar) + } + + private func setWeatherImage(weather: String) { + switch weather { + case "cloudBolt": + weatherImage.image = UIImage(named: "cloudBolt") + case "cloudMoon": + weatherImage.image = UIImage(named: "cloudMoon") + case "softRain": + weatherImage.image = UIImage(named: "softRain") + case "heavyRain": + weatherImage.image = UIImage(named: "heavyRain") + case "rainWithSun": + weatherImage.image = UIImage(named: "rainWithSun") + default: + weatherImage.image = UIImage(named: "cloudMoon") + } + } +} diff --git a/assignment1/assignment1/Presentations/WeatherDetail/TenDaysTableView/TenDaysTableViewData.swift b/assignment1/assignment1/Presentations/WeatherDetail/TenDaysTableView/TenDaysTableViewData.swift new file mode 100644 index 0000000..330ced0 --- /dev/null +++ b/assignment1/assignment1/Presentations/WeatherDetail/TenDaysTableView/TenDaysTableViewData.swift @@ -0,0 +1,67 @@ +// +// TenDaysTableViewData.swift +// assignment1 +// +// Created by Seonwoo Kim on 2023/11/08. +// + +import Foundation + +struct TenDaysTableViewData { + let date: String + let weatherImage: String + let minTemp: String + let maxTemp: String + var degreeBar: String + + init(date: String, weatherImage: String, minTemp: String, maxTemp: String, degreeBar: String) { + self.date = date + self.weatherImage = weatherImage + self.minTemp = minTemp + self.maxTemp = maxTemp + self.degreeBar = degreeBar + } +} + + +var tenDaysTableViewData: [TenDaysTableViewData] = [.init(date: "오늘", + weatherImage: "softRain", + minTemp: "25°", + maxTemp: "25°", + degreeBar: "tempBar1"), + .init(date: "오늘", + weatherImage: "softRain", + minTemp: "25°", + maxTemp: "25°", + degreeBar: "tempBar1"), + .init(date: "오늘", + weatherImage: "softRain", + minTemp: "25°", + maxTemp: "25°", + degreeBar: "tempBar1"), + .init(date: "오늘", + weatherImage: "softRain", + minTemp: "25°", + maxTemp: "25°", + degreeBar: "tempBar1"), + .init(date: "오늘", + weatherImage: "softRain", + minTemp: "25°", + maxTemp: "25°", + degreeBar: "tempBar1"), + .init(date: "오늘", + weatherImage: "softRain", + minTemp: "25°", + maxTemp: "25°", + degreeBar: "tempBar1"), + .init(date: "오늘", + weatherImage: "softRain", + minTemp: "25°", + maxTemp: "25°", + degreeBar: "tempBar1"), + .init(date: "오늘", + weatherImage: "softRain", + minTemp: "25°", + maxTemp: "25°", + degreeBar: "tempBar1"), +] diff --git a/assignment1/assignment1/Presentations/WeatherDetail/ViewControllers/WheatherDetailViewController.swift b/assignment1/assignment1/Presentations/WeatherDetail/ViewControllers/WheatherDetailViewController.swift deleted file mode 100644 index 9e10842..0000000 --- a/assignment1/assignment1/Presentations/WeatherDetail/ViewControllers/WheatherDetailViewController.swift +++ /dev/null @@ -1,55 +0,0 @@ -import UIKit - -class WheatherDetailViewController: UIViewController { - private let weatherDetailView = WheatherDetailMain() - private let backgroundImageView = UIImageView(image: UIImage(named: "background")) - - override func viewDidLoad() { - super.viewDidLoad() - // 폰트 체크 하기 - UIFont.familyNames.sorted().forEach { familyName in - print("*** \(familyName) ***") - UIFont.fontNames(forFamilyName: familyName).forEach { fontName in - print("\(fontName)") - } - print("——————————") - } - addTarget() - } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - } - - override func loadView() { - view = weatherDetailView - } - - override func viewDidLayoutSubviews() { - super.viewDidLayoutSubviews() - - setBackgroundImage() - } - - deinit { - print(#function) - } - - private func addTarget() { - weatherDetailView.bottomBar.listButton.addTarget(self, action: #selector(tapListView), for: .touchUpInside) - } - - @objc func tapListView() { - print("taptaptap") - self.navigationController?.popViewController(animated: true) - } -} - -extension WheatherDetailViewController { - private func setBackgroundImage() { - backgroundImageView.contentMode = .scaleAspectFill - backgroundImageView.frame = view.bounds - view.insertSubview(backgroundImageView, at: 0) - } -} - diff --git a/assignment1/assignment1/Presentations/WeatherDetail/Views/WheatherDetailMain.swift b/assignment1/assignment1/Presentations/WeatherDetail/Views/WheatherDetailMain.swift deleted file mode 100644 index d28e37b..0000000 --- a/assignment1/assignment1/Presentations/WeatherDetail/Views/WheatherDetailMain.swift +++ /dev/null @@ -1,246 +0,0 @@ -import UIKit - -class WheatherDetailMain: UIView { - private let verticalScrollView = UIScrollView() - private var verticalContentView = UIView() - private let horizontalScrollView = UIScrollView() - private var cityLabel = UILabel() - private var tempLabel = UILabel() - private var wheatherStatusLabel = UILabel() - private var minTempLabel = UILabel() - private var maxTempLabel = UILabel() - private var wheatherDescriptionLabel = UILabel() - private var horizontalWeatherStackView = UIStackView() - private var lineView = UIView() - private let descriptionView = UIStackView() - var bottomBar = BottomAppBar() - private let backgroundImageView = UIImageView(image: UIImage(named: "background")) - - - let timelyWeatherInfoView1 = WheatherDetailListView(time: "1", weather: "cloudBolt", temperature: "25°") - let timelyWeatherInfoView2 = WheatherDetailListView(time: "2", weather: "softRain", temperature: "24°") - let timelyWeatherInfoView3 = WheatherDetailListView(time: "3", weather: "cloudBolt", temperature: "23°") - let timelyWeatherInfoView4 = WheatherDetailListView(time: "4", weather: "softRain", temperature: "22°") - let timelyWeatherInfoView5 = WheatherDetailListView(time: "5", weather: "softRain", temperature: "21°") - let timelyWeatherInfoView6 = WheatherDetailListView(time: "6", weather: "cloudBolt", temperature: "20°") - let timelyWeatherInfoView7 = WheatherDetailListView(time: "7", weather: "cloudBolt", temperature: "20°") - let timelyWeatherInfoView8 = WheatherDetailListView(time: "8", weather: "softRain", temperature: "21°") - let timelyWeatherInfoView9 = WheatherDetailListView(time: "9", weather: "cloudBolt", temperature: "22°") - let timelyWeatherInfoView10 = WheatherDetailListView(time: "10", weather: "softRain", temperature: "23°") - let timelyWeatherInfoView11 = WheatherDetailListView(time: "11", weather: "cloudBolt", temperature: "24°") - let timelyWeatherInfoView12 = WheatherDetailListView(time: "12", weather: "cloudBolt", temperature: "25°") - - let totalWidth = CGFloat(70 * 12) - - override init(frame: CGRect) { - super.init(frame: frame) - self.setLayout() - self.setStyle() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -} - -extension WheatherDetailMain { - - private func setStyle() { - - [verticalScrollView].forEach { - $0.alwaysBounceVertical = true - $0.showsVerticalScrollIndicator = false - } - - [horizontalWeatherStackView].forEach{ - $0.axis = .horizontal - $0.distribution = .equalSpacing - $0.spacing = 10 - } - - [horizontalScrollView].forEach { - $0.showsHorizontalScrollIndicator = false - } - - [cityLabel].forEach { - $0.textColor = .white - $0.text = "의정부시" - $0.font = UIFont(name: "SFProDisplay-Regular", size: 36) - } - - [tempLabel].forEach { - $0.textColor = .white - $0.text = "21°" - $0.font = UIFont(name: "SFProDisplay-Regular", size: 102) - } - - [wheatherStatusLabel].forEach { - $0.textColor = .white - $0.text = "흐림" - $0.font = UIFont(name: "SFProDisplay-Regular", size: 25) - } - - [minTempLabel].forEach { - $0.textColor = .white - $0.text = "최저:19°" - $0.font = UIFont(name: "SFProDisplay-Regular", size: 23) - } - - [maxTempLabel].forEach { - $0.textColor = .white - $0.text = "최고:29°" - $0.font = UIFont(name: "SFProDisplay-Regular", size: 23) - } - - [wheatherDescriptionLabel].forEach { - $0.textColor = .white - $0.text = "08:00~09:00에 강우 상태가, 18:00에 한때 흐린 상태가 예상됩니다." - $0.font = UIFont(name: "SFProDisplay-Regular", size: 18) - $0.numberOfLines = 2 - } - - [descriptionView].forEach { - $0.backgroundColor = UIColor.black.withAlphaComponent(0.1) - $0.axis = .vertical - $0.alignment = .center - $0.layer.cornerRadius = 20 - $0.layer.borderColor = UIColor.white.withAlphaComponent(0.3).cgColor - $0.layer.borderWidth = 0.5 - } - [lineView].forEach{ - $0.backgroundColor = UIColor.white.withAlphaComponent(0.3) - } - - [timelyWeatherInfoView1, timelyWeatherInfoView2, timelyWeatherInfoView3, timelyWeatherInfoView4, timelyWeatherInfoView5, timelyWeatherInfoView6, timelyWeatherInfoView7,timelyWeatherInfoView8, timelyWeatherInfoView9, timelyWeatherInfoView10, timelyWeatherInfoView11, timelyWeatherInfoView12].forEach { - $0.translatesAutoresizingMaskIntoConstraints = false - ($0.widthAnchor.constraint(equalToConstant: 65)).isActive = true - ($0.heightAnchor.constraint(equalToConstant: 150)).isActive = true - horizontalWeatherStackView.addArrangedSubview($0) - } - - } - - private func setLayout() { - [verticalScrollView, bottomBar].forEach { - $0.translatesAutoresizingMaskIntoConstraints = false - self.addSubview($0) - } - - verticalScrollView.addSubview(verticalContentView) - verticalContentView.translatesAutoresizingMaskIntoConstraints = false - - verticalContentView.addSubview(cityLabel) - verticalContentView.addSubview(tempLabel) - verticalContentView.addSubview(wheatherStatusLabel) - verticalContentView.addSubview(minTempLabel) - verticalContentView.addSubview(maxTempLabel) - verticalContentView.addSubview(descriptionView) - - [cityLabel,tempLabel,wheatherStatusLabel,minTempLabel,maxTempLabel,descriptionView,horizontalScrollView,wheatherDescriptionLabel,horizontalWeatherStackView,lineView].forEach { - $0.translatesAutoresizingMaskIntoConstraints = false - } - - descriptionView.addArrangedSubview(wheatherDescriptionLabel) - descriptionView.addArrangedSubview(lineView) - descriptionView.addArrangedSubview(horizontalScrollView) - - horizontalScrollView.addSubview(horizontalWeatherStackView) - - // verticalScrollView 제약 조건 설정 - NSLayoutConstraint.activate([ - verticalScrollView.topAnchor.constraint(equalTo: self.topAnchor), - verticalScrollView.bottomAnchor.constraint(equalTo: bottomBar.topAnchor), - verticalScrollView.leadingAnchor.constraint(equalTo: self.leadingAnchor), - verticalScrollView.trailingAnchor.constraint(equalTo: self.trailingAnchor) - ]) - - - NSLayoutConstraint.activate([ - verticalContentView.topAnchor.constraint(equalTo: verticalScrollView.contentLayoutGuide.topAnchor), - verticalContentView.bottomAnchor.constraint(equalTo: verticalScrollView.contentLayoutGuide.bottomAnchor), - verticalContentView.leadingAnchor.constraint(equalTo: verticalScrollView.contentLayoutGuide.leadingAnchor), - verticalContentView.trailingAnchor.constraint(equalTo: verticalScrollView.contentLayoutGuide.trailingAnchor), - ]) - - verticalContentView.widthAnchor.constraint(equalTo: verticalScrollView.widthAnchor).isActive = true - let contentViewHeight = verticalContentView.heightAnchor.constraint(greaterThanOrEqualTo: self.heightAnchor) - contentViewHeight.priority = .defaultLow - contentViewHeight.isActive = true - - // bottomBar 제약 조건 설정 - NSLayoutConstraint.activate([ - bottomBar.bottomAnchor.constraint(equalTo: self.bottomAnchor), - bottomBar.leadingAnchor.constraint(equalTo: self.leadingAnchor), - bottomBar.trailingAnchor.constraint(equalTo: self.trailingAnchor), - bottomBar.heightAnchor.constraint(equalToConstant: 80) - ]) - - // cityLabel, tempLabel, wheatherStatusLabel, minTempLabel, maxTempLabel, descriptionView 제약 조건 설정 - NSLayoutConstraint.activate([ - cityLabel.topAnchor.constraint(equalTo: verticalContentView.topAnchor, constant: 50), - cityLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor) - ]) - - NSLayoutConstraint.activate([ - tempLabel.topAnchor.constraint(equalTo: cityLabel.bottomAnchor, constant: 5), - tempLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor) - ]) - - NSLayoutConstraint.activate([ - wheatherStatusLabel.topAnchor.constraint(equalTo: tempLabel.bottomAnchor, constant: 5), - wheatherStatusLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor) - ]) - - NSLayoutConstraint.activate([ - maxTempLabel.topAnchor.constraint(equalTo: wheatherStatusLabel.bottomAnchor, constant: 3), - maxTempLabel.trailingAnchor.constraint(equalTo: self.centerXAnchor, constant: -3) - ]) - - NSLayoutConstraint.activate([ - minTempLabel.topAnchor.constraint(equalTo: wheatherStatusLabel.bottomAnchor, constant: 3), - minTempLabel.leadingAnchor.constraint(equalTo: self.centerXAnchor, constant: 3) - ]) - - NSLayoutConstraint.activate([ - descriptionView.topAnchor.constraint(equalTo: maxTempLabel.bottomAnchor, constant: 50), - descriptionView.centerXAnchor.constraint(equalTo: centerXAnchor), - descriptionView.heightAnchor.constraint(equalToConstant: 212), - descriptionView.widthAnchor.constraint(equalToConstant: 345) - ]) - - // wheatherDescriptionLabel, lineView 제약 조건 설정 - NSLayoutConstraint.activate([ - wheatherDescriptionLabel.topAnchor.constraint(equalTo: descriptionView.topAnchor, constant: 15), - wheatherDescriptionLabel.leadingAnchor.constraint(equalTo: descriptionView.leadingAnchor, constant: 13), - wheatherDescriptionLabel.trailingAnchor.constraint(equalTo: descriptionView.trailingAnchor, constant: -13), - wheatherDescriptionLabel.bottomAnchor.constraint(equalTo: lineView.topAnchor, constant: -15) - ]) - - NSLayoutConstraint.activate([ - lineView.topAnchor.constraint(equalTo: wheatherDescriptionLabel.bottomAnchor, constant: 20), - lineView.leadingAnchor.constraint(equalTo: descriptionView.leadingAnchor, constant: 13), - lineView.trailingAnchor.constraint(equalTo: descriptionView.trailingAnchor, constant: -13), - lineView.heightAnchor.constraint(equalToConstant: 0.3) - ]) - - // horizontalScrollView 제약 조건 설정 - NSLayoutConstraint.activate([ - horizontalScrollView.topAnchor.constraint(equalTo: lineView.bottomAnchor), - horizontalScrollView.bottomAnchor.constraint(equalTo: descriptionView.bottomAnchor), - horizontalScrollView.leadingAnchor.constraint(equalTo: descriptionView.leadingAnchor), - horizontalScrollView.trailingAnchor.constraint(equalTo: descriptionView.trailingAnchor) - ]) - - - NSLayoutConstraint.activate([ - horizontalWeatherStackView.topAnchor.constraint(equalTo: horizontalScrollView.topAnchor), - horizontalWeatherStackView.leadingAnchor.constraint(equalTo: horizontalScrollView.leadingAnchor), - horizontalWeatherStackView.trailingAnchor.constraint(equalTo: horizontalScrollView.trailingAnchor) - - ]) - - - } -} - -// 가로 스크롤 수정하기 diff --git a/assignment1/assignment1/Presentations/WeatherDetail/Views/wheatherDetailListView.swift b/assignment1/assignment1/Presentations/WeatherDetail/Views/wheatherDetailListView.swift deleted file mode 100644 index 76df9e4..0000000 --- a/assignment1/assignment1/Presentations/WeatherDetail/Views/wheatherDetailListView.swift +++ /dev/null @@ -1,84 +0,0 @@ -// -// wheatherDetailListView.swift -// assignment1 -// -// Created by Seonwoo Kim on 2023/10/25. -// - -import Foundation - -import UIKit - -class WheatherDetailListView: UIView { - - let timeLabel: UILabel = { - let label = UILabel() - label.textColor = .white - label.font = UIFont(name: "SFProDisplay-Regular", size: 17) - return label - }() - - let weatherImageView: UIImageView = { - let imageView = UIImageView() - imageView.contentMode = .scaleAspectFit - return imageView - }() - - let temperatureLabel: UILabel = { - let label = UILabel() - label.textColor = .white - label.font = UIFont(name: "SFProDisplay-Regular", size: 19) - return label - }() - - init(time: String, weather: String, temperature: String) { - super.init(frame: .zero) - timeLabel.text = "\(time)시" - setWeatherImage(weather: weather) - temperatureLabel.text = "\(temperature)" - setLayout() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - private func setLayout() { - [timeLabel, weatherImageView, temperatureLabel].forEach { - $0.translatesAutoresizingMaskIntoConstraints = false - addSubview($0) - } - - NSLayoutConstraint.activate([ - timeLabel.topAnchor.constraint(equalTo: topAnchor, constant: 15), - timeLabel.centerXAnchor.constraint(equalTo: centerXAnchor) - ]) - - NSLayoutConstraint.activate([ - weatherImageView.topAnchor.constraint(equalTo: timeLabel.bottomAnchor, constant: 15), - weatherImageView.centerXAnchor.constraint(equalTo: timeLabel.centerXAnchor) - ]) - - NSLayoutConstraint.activate([ - temperatureLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -15), - temperatureLabel.centerXAnchor.constraint(equalTo: timeLabel.centerXAnchor) - ]) - } - - private func setWeatherImage(weather: String) { - switch weather { - case "cloudBolt": - weatherImageView.image = UIImage(named: "cloudBolt") - case "cloudMoon": - weatherImageView.image = UIImage(named: "cloudMoon") - case "softRain": - weatherImageView.image = UIImage(named: "softRain") - case "heavyRain": - weatherImageView.image = UIImage(named: "heavyRain") - case "rainWithSun": - weatherImageView.image = UIImage(named: "rainWithSun") - default: - weatherImageView.image = UIImage(named: "cloudMoon") - } - } -} diff --git a/assignment1/assignment1/Presentations/WeatherDetail/WeatherCollectionView/WeatherCollectionViewData.swift b/assignment1/assignment1/Presentations/WeatherDetail/WeatherCollectionView/WeatherCollectionViewData.swift new file mode 100644 index 0000000..c11ddd6 --- /dev/null +++ b/assignment1/assignment1/Presentations/WeatherDetail/WeatherCollectionView/WeatherCollectionViewData.swift @@ -0,0 +1,34 @@ +// +// WeatherCollectionViewData.swift +// assignment1 +// +// Created by Seonwoo Kim on 2023/11/07. +// + +import Foundation + +struct WeatherCollectionViewData { + let time: String + let weather: String + let temperature: String + + + init(time: String, weather: String, temperature: String) { + self.time = time + self.weather = weather + self.temperature = temperature + } +} + +var weatherCollectionViewData: [WeatherCollectionViewData] = [.init(time: "12시", weather: "cloudBolt", temperature: "21°"), + .init(time: "12시", weather: "cloudBolt", temperature: "21°"), + .init(time: "12시", weather: "cloudBolt", temperature: "21°"), + .init(time: "12시", weather: "cloudBolt", temperature: "21°"), + .init(time: "12시", weather: "cloudBolt", temperature: "21°"), + .init(time: "12시", weather: "cloudBolt", temperature: "21°"), + .init(time: "12시", weather: "cloudBolt", temperature: "21°"), + .init(time: "12시", weather: "cloudBolt", temperature: "21°"), + .init(time: "12시", weather: "cloudBolt", temperature: "21°"), + .init(time: "12시", weather: "cloudBolt", temperature: "21°"), + .init(time: "12시", weather: "cloudBolt", temperature: "21°"), +] diff --git a/assignment1/assignment1/Presentations/WeatherDetail/WeatherCollectionView/WeatherDetailCollectionViewCell.swift b/assignment1/assignment1/Presentations/WeatherDetail/WeatherCollectionView/WeatherDetailCollectionViewCell.swift new file mode 100644 index 0000000..aaf114e --- /dev/null +++ b/assignment1/assignment1/Presentations/WeatherDetail/WeatherCollectionView/WeatherDetailCollectionViewCell.swift @@ -0,0 +1,82 @@ +// +// WeatherDetailCollectionViewCell.swift +// assignment1 +// +// Created by Seonwoo Kim on 2023/11/07. +// + +import UIKit +import SnapKit +import Then + +class WeatherDetailCollectionViewCell: UICollectionViewCell { + static let identifier: String = "WeatherDetailCollectionViewCell" + + private var timeLabel = UILabel().then { + $0.textColor = .white + $0.font = UIFont(name: "SFProDisplay-Regular", size: 17) + } + + private var weatherImageView = UIImageView().then { + $0.contentMode = .scaleAspectFit + } + + private var temperatureLabel = UILabel().then { + $0.textColor = .white + $0.font = UIFont(name: "SFProDisplay-Regular", size: 19) + } + + override init(frame: CGRect) { + super.init(frame: frame) + setLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setLayout() { + self.addSubview(timeLabel) + self.addSubview(weatherImageView) + self.addSubview(temperatureLabel) + + timeLabel.snp.makeConstraints { + $0.top.equalToSuperview().offset(4) + $0.centerX.equalToSuperview() + } + + weatherImageView.snp.makeConstraints { + $0.top.equalTo(timeLabel.snp.bottom).offset(14) + $0.centerX.equalTo(timeLabel) + } + + temperatureLabel.snp.makeConstraints { + $0.bottom.equalToSuperview().offset(4) + $0.centerX.equalTo(timeLabel) + } + } + + func bindData(data: WeatherCollectionViewData) { + self.timeLabel.text = data.time + setWeatherImage(weather: data.weather) + self.temperatureLabel.text = data.temperature + } + + private func setWeatherImage(weather: String) { + switch weather { + case "cloudBolt": + weatherImageView.image = UIImage(named: "cloudBolt") + case "cloudMoon": + weatherImageView.image = UIImage(named: "cloudMoon") + case "softRain": + weatherImageView.image = UIImage(named: "softRain") + case "heavyRain": + weatherImageView.image = UIImage(named: "heavyRain") + case "rainWithSun": + weatherImageView.image = UIImage(named: "rainWithSun") + default: + weatherImageView.image = UIImage(named: "cloudMoon") + } + } + +} diff --git a/assignment1/assignment1/Presentations/WeatherList/ViewControllers/WhetherListViewController.swift b/assignment1/assignment1/Presentations/WeatherList/ViewControllers/WhetherListViewController.swift deleted file mode 100644 index d2dcba4..0000000 --- a/assignment1/assignment1/Presentations/WeatherList/ViewControllers/WhetherListViewController.swift +++ /dev/null @@ -1,98 +0,0 @@ -// -// ViewController.swift -// assignment1 -// -// Created by Seonwoo Kim on 2023/10/15. -// - -import UIKit - -class WheatherListViewController: UIViewController { - private let homeView = WheatherListMain() - private let moreButtonItem = UIBarButtonItem() - private let locationSearchController = UISearchController() - - - override func viewDidLoad() { - super.viewDidLoad() - // 폰트 체크 하기 - UIFont.familyNames.sorted().forEach { familyName in - print("*** \(familyName) ***") - UIFont.fontNames(forFamilyName: familyName).forEach { fontName in - print("\(fontName)") - } - print("——————————") - } - self.addTarget() - } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - setNavigation() - setSearchController() - } - - override func loadView() { - self.view = homeView - setNavigation() - setSearchController() - } - private func addTarget() { - [homeView.seoulWeatherInfoView,homeView.seoulWeatherInfoView1,homeView.seoulWeatherInfoView2,homeView.seoulWeatherInfoView3,homeView.seoulWeatherInfoView4,homeView.seoulWeatherInfoView5,homeView.seoulWeatherInfoView6,homeView.seoulWeatherInfoView7].forEach{ - $0.addTarget(self, action: #selector(tapListView), for: .touchUpInside) - } - - } - - @objc func tapListView() { - let weatherDetailViewController = WheatherDetailViewController() - - self.navigationController?.pushViewController(weatherDetailViewController, animated: true) - self.navigationController?.isNavigationBarHidden = true - } - - deinit { - print(#function) - } -} - -extension WheatherListViewController { - private func setSearchController() { - [locationSearchController].forEach{ - $0.searchBar.searchTextField.attributedPlaceholder = NSAttributedString(string: "도시 또는 공항 검색", attributes: [NSAttributedString.Key.foregroundColor : #colorLiteral(red: 0.6178889275, green: 0.6178889275, blue: 0.6178889275, alpha: 1)]) - $0.searchBar.searchTextField.backgroundColor = #colorLiteral(red: 0.1353607476, green: 0.1353607476, blue: 0.1353607476, alpha: 1) - $0.searchBar.searchTextField.textColor = .white - $0.searchBar.tintColor = .white - $0.searchBar.setValue("취소", forKey: "cancelButtonText") - $0.hidesNavigationBarDuringPresentation = true - } - - self.navigationItem.searchController = locationSearchController - self.navigationItem.hidesSearchBarWhenScrolling = false - self.locationSearchController.searchBar.searchTextField.textColor = .white - self.locationSearchController.searchBar.searchTextField.leftView?.tintColor = #colorLiteral(red: 0.6178889275, green: 0.6178889275, blue: 0.6178889275, alpha: 1) - } - - private func setNavigation() { - [moreButtonItem].forEach { - $0.isHidden = false - $0.image = UIImage(named: "moreIcon") - $0.tintColor = .white - } - - self.view.backgroundColor = .black - self.navigationItem.rightBarButtonItem = moreButtonItem - self.navigationItem.title = "날씨" - - self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] - // 스크롤시 작게 보이는 타이틀 - self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] - self.navigationController?.navigationBar.barTintColor = .black - // 스크롤 시 보이는 뷰의 백그라운드 - self.navigationController?.navigationBar.prefersLargeTitles = true - // 라지 사이즈 타이틀이 보이는 것 - } - - - -} diff --git a/assignment1/assignment1/Presentations/WeatherList/Views/CityListView.swift b/assignment1/assignment1/Presentations/WeatherList/Views/CityListView.swift deleted file mode 100644 index af906b2..0000000 --- a/assignment1/assignment1/Presentations/WeatherList/Views/CityListView.swift +++ /dev/null @@ -1,98 +0,0 @@ -import UIKit - -class CityListView: UIButton { - - weak var delegate: WeatherInfoViewDelegate? - - let backgroundImageView = UIImageView(image: UIImage(named: "listBackground")) - let myLocationLabel = UILabel() - let locationLabel = UILabel() - let weatherLabel = UILabel() - let temperatureLabel = UILabel() - let maxtemperatureLabel = UILabel() - let mintemperatureLabel = UILabel() - - init(location: String, weather: String, temperature: String, maxTemperature: String, minTemperature: String) { - super.init(frame: .zero) - locationLabel.text = location - weatherLabel.text = weather - temperatureLabel.text = temperature - maxtemperatureLabel.text = "최고:\(maxTemperature)" - mintemperatureLabel.text = "최저:\(minTemperature)" - - self.setLayout() - self.setStyle() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - - private func setLayout(){ - [backgroundImageView, myLocationLabel, locationLabel, weatherLabel, temperatureLabel, maxtemperatureLabel, mintemperatureLabel].forEach { - $0.translatesAutoresizingMaskIntoConstraints = false - addSubview($0) - } - - NSLayoutConstraint.activate([ - backgroundImageView.topAnchor.constraint(equalTo: topAnchor), - backgroundImageView.leadingAnchor.constraint(equalTo: leadingAnchor), - backgroundImageView.trailingAnchor.constraint(equalTo: trailingAnchor), - backgroundImageView.bottomAnchor.constraint(equalTo: bottomAnchor) - ]) - - NSLayoutConstraint.activate([ - myLocationLabel.topAnchor.constraint(equalTo: topAnchor, constant: 7), - myLocationLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 15) - ]) - - NSLayoutConstraint.activate([ - locationLabel.topAnchor.constraint(equalTo: myLocationLabel.bottomAnchor), - locationLabel.leadingAnchor.constraint(equalTo: myLocationLabel.leadingAnchor) - ]) - - NSLayoutConstraint.activate([ - weatherLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -7), - weatherLabel.leadingAnchor.constraint(equalTo: myLocationLabel.leadingAnchor) - ]) - - NSLayoutConstraint.activate([ - temperatureLabel.topAnchor.constraint(equalTo: myLocationLabel.topAnchor), - temperatureLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -15) - ]) - - NSLayoutConstraint.activate([ - mintemperatureLabel.bottomAnchor.constraint(equalTo: weatherLabel.bottomAnchor), - mintemperatureLabel.trailingAnchor.constraint(equalTo: temperatureLabel.trailingAnchor) - ]) - - NSLayoutConstraint.activate([ - maxtemperatureLabel.bottomAnchor.constraint(equalTo: weatherLabel.bottomAnchor), - maxtemperatureLabel.trailingAnchor.constraint(equalTo: mintemperatureLabel.leadingAnchor, constant: -5) - ]) - - isUserInteractionEnabled = true - } - - private func setStyle() { - backgroundImageView.contentMode = .scaleAspectFill - - [ myLocationLabel, locationLabel, weatherLabel, temperatureLabel, maxtemperatureLabel, mintemperatureLabel].forEach { - $0.textColor = .white - } - - myLocationLabel.text = "나의 위치" - myLocationLabel.font = UIFont(name: "SFProDisplay-Regular", size: 25) - - - // locationLabel.text = "나의 위치" - locationLabel.font = UIFont(name: "SFProDisplay-Regular", size: 17) - temperatureLabel.font = UIFont(name: "SFProDisplay-Regular", size: 52) - } - - - - -} - diff --git a/assignment1/assignment1/Presentations/WeatherList/Views/WheatherListMain.swift b/assignment1/assignment1/Presentations/WeatherList/Views/WheatherListMain.swift deleted file mode 100644 index e3595f9..0000000 --- a/assignment1/assignment1/Presentations/WeatherList/Views/WheatherListMain.swift +++ /dev/null @@ -1,99 +0,0 @@ -// -// WheatherListMain.swift -// assignment1 -// -// Created by Seonwoo Kim on 2023/10/20. -// - -import UIKit - -final class WheatherListMain: UIView { - private let scrollView = UIScrollView() - private var contentView = UIView() - private var weatherInfoStackView = UIStackView() - - override init(frame: CGRect) { - super.init(frame: frame) - self.setLayout() - self.setStyle() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - let seoulWeatherInfoView = CityListView(location: "서울", weather: "흐림", temperature: "25°", maxTemperature: "27°", minTemperature: "23°") - let seoulWeatherInfoView1 = CityListView(location: "서울", weather: "흐림", temperature: "25°", maxTemperature: "27°", minTemperature: "23°") - let seoulWeatherInfoView2 = CityListView(location: "서울", weather: "흐림", temperature: "25°", maxTemperature: "27°", minTemperature: "23°") - let seoulWeatherInfoView3 = CityListView(location: "서울", weather: "흐림", temperature: "25°", maxTemperature: "27°", minTemperature: "23°") - let seoulWeatherInfoView4 = CityListView(location: "서울", weather: "흐림", temperature: "25°", maxTemperature: "27°", minTemperature: "23°") - let seoulWeatherInfoView5 = CityListView(location: "서울", weather: "흐림", temperature: "25°", maxTemperature: "27°", minTemperature: "23°") - let seoulWeatherInfoView6 = CityListView(location: "서울", weather: "흐림", temperature: "25°", maxTemperature: "27°", minTemperature: "23°") - let seoulWeatherInfoView7 = CityListView(location: "서울", weather: "흐림", temperature: "25°", maxTemperature: "27°", minTemperature: "23°") - -} - -extension WheatherListMain { - private func setLayout() { - self.addSubview(scrollView) - scrollView.translatesAutoresizingMaskIntoConstraints = false - - NSLayoutConstraint.activate([ - scrollView.topAnchor.constraint(equalTo: self.topAnchor), - scrollView.bottomAnchor.constraint(equalTo: self.bottomAnchor), - scrollView.leadingAnchor.constraint(equalTo: self.leadingAnchor), - scrollView.trailingAnchor.constraint(equalTo: self.trailingAnchor), - ]) - - scrollView.addSubview(contentView) - contentView.translatesAutoresizingMaskIntoConstraints = false - - NSLayoutConstraint.activate([ - contentView.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor), - contentView.bottomAnchor.constraint(equalTo: scrollView.contentLayoutGuide.bottomAnchor), - contentView.leadingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.leadingAnchor), - contentView.trailingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.trailingAnchor), - contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor), - ]) - - [weatherInfoStackView].forEach { - $0.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview($0) - } - - NSLayoutConstraint.activate([ - weatherInfoStackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 7), - weatherInfoStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16), - weatherInfoStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16), - weatherInfoStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor) - ]) - } - - - private func setStyle() { - [scrollView].forEach{ - $0.alwaysBounceVertical = true - } - - [weatherInfoStackView].forEach() { - $0.axis = .vertical - $0.distribution = .equalSpacing - $0.spacing = 20 - } - - [weatherInfoStackView].forEach() { - $0.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview($0) - } - - - [seoulWeatherInfoView,seoulWeatherInfoView1,seoulWeatherInfoView2,seoulWeatherInfoView3,seoulWeatherInfoView4,seoulWeatherInfoView5,seoulWeatherInfoView6,seoulWeatherInfoView7].forEach() { - $0.translatesAutoresizingMaskIntoConstraints = false - ($0.heightAnchor.constraint(equalToConstant: 120)).isActive = true - - weatherInfoStackView.addArrangedSubview($0) - } - } -} - - diff --git a/assignment1/assignment1/Presentations/WeatherList/WeatherListTableViewData.swift b/assignment1/assignment1/Presentations/WeatherList/WeatherListTableViewData.swift new file mode 100644 index 0000000..47f8c84 --- /dev/null +++ b/assignment1/assignment1/Presentations/WeatherList/WeatherListTableViewData.swift @@ -0,0 +1,35 @@ +// +// WheatherListData.swift +// assignment1 +// +// Created by Seonwoo Kim on 2023/11/06. +// + +import Foundation + + +struct WeatherListViewData { + let location: String + let weather: String + let temperature: String + let maxTemperature: String + let minTemperature: String + + init(location: String, weather: String, temperature: String, maxTemperature: String, minTemperature: String) { + self.location = location + self.weather = weather + self.temperature = temperature + self.maxTemperature = maxTemperature + self.minTemperature = minTemperature + } +} + +var weatherListViewData: [WeatherListViewData] = [ + .init(location: "Seoul", weather: "흐림", temperature: "25°", maxTemperature: "최고:27°", minTemperature: "최저:23°"), + .init(location: "Sydney", weather: "흐림", temperature: "25°", maxTemperature: "최고:27°", minTemperature: "최저:23°"), + .init(location: "Incheon", weather: "흐림", temperature: "25°", maxTemperature: "최고:27°", minTemperature: "최저:23°"), + .init(location: "Tokyo", weather: "흐림", temperature: "25°", maxTemperature: "최고:27°", minTemperature: "최저:23°"), + .init(location: "Texas", weather: "흐림", temperature: "25°", maxTemperature: "최고:27°", minTemperature: "최저:23°"), +] + + diff --git a/assignment1/assignment1/Presentations/WeatherList/WeatherListViewController.swift b/assignment1/assignment1/Presentations/WeatherList/WeatherListViewController.swift new file mode 100644 index 0000000..112d88b --- /dev/null +++ b/assignment1/assignment1/Presentations/WeatherList/WeatherListViewController.swift @@ -0,0 +1,132 @@ +// +// WheatherListViewController.swift +// assignment1 +// +// Created by Seonwoo Kim on 2023/11/06. +// + +import UIKit +import SnapKit +import Then + +class WeatherListViewController: UIViewController { + + private let tableView = UITableView(frame: .zero, style: .plain).then { + $0.backgroundColor = .black + } + + private let moreButtonItem = UIBarButtonItem() + private let locationSearchController = UISearchController() + + override func viewDidLoad() { + super.viewDidLoad() + setSearchController() + setNavigation() + setTableViewConfig() + setLayout() + } + + private func reload() { + self.tableView.reloadData() + } + + private func setLayout() { + self.view.addSubview(tableView) + tableView.snp.makeConstraints { + $0.edges.equalToSuperview() + } + } + + private func setTableViewConfig() { + self.tableView.register(WetherListTableViewCell.self, + forCellReuseIdentifier: WetherListTableViewCell.identifier) + self.tableView.delegate = self + self.tableView.dataSource = self + } + + private func setSearchController() { + let locationSearchController = UISearchController().then { + $0.searchBar.searchTextField.attributedPlaceholder = NSAttributedString(string: "도시 또는 공항 검색", attributes: [NSAttributedString.Key.foregroundColor : #colorLiteral(red: 0.6178889275, green: 0.6178889275, blue: 0.6178889275, alpha: 1)]) + $0.searchBar.searchTextField.backgroundColor = #colorLiteral(red: 0.1353607476, green: 0.1353607476, blue: 0.1353607476, alpha: 1) + $0.searchBar.searchTextField.textColor = .white + $0.searchBar.tintColor = .white + $0.searchBar.setValue("취소", forKey: "cancelButtonText") + $0.hidesNavigationBarDuringPresentation = true + let textFieldInsideSearchBar = navigationItem.searchController?.searchBar.value(forKey: "searchField") as? UITextField + } + + self.navigationItem.searchController = locationSearchController + self.navigationItem.hidesSearchBarWhenScrolling = false + self.locationSearchController.searchBar.searchTextField.textColor = .white + self.locationSearchController.searchBar.searchTextField.leftView?.tintColor = #colorLiteral(red: 0.6178889275, green: 0.6178889275, blue: 0.6178889275, alpha: 1) + navigationItem.searchController?.searchResultsUpdater = self + } + + private func setNavigation() { + let moreButtonItem = UIBarButtonItem().then { + $0.isHidden = false + $0.image = UIImage(named: "moreIcon") + $0.tintColor = .white + } + + self.view.backgroundColor = .black + self.navigationItem.rightBarButtonItem = moreButtonItem + self.navigationItem.title = "날씨" + + self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] + // 스크롤시 작게 보이는 타이틀 + self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] + self.navigationController?.navigationBar.barTintColor = .black + // 스크롤 시 보이는 뷰의 백그라운드 + self.navigationController?.navigationBar.prefersLargeTitles = true + // 라지 사이즈 타이틀이 보이는 것 + } + + @objc func tapListView() { + let weatherDetailViewController = WeatherDetailViewController() + + self.navigationController?.pushViewController(weatherDetailViewController, animated: true) + self.navigationController?.isNavigationBarHidden = true + } +} + +extension WeatherListViewController: UITableViewDelegate {} +extension WeatherListViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return isFiltering ? filteredLocationData.count : weatherListViewData.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + guard let cell = tableView.dequeueReusableCell(withIdentifier: WetherListTableViewCell.identifier, for: indexPath) as? WetherListTableViewCell else { return UITableViewCell() } + + let dataToDisplay = self.isFiltering ? filteredLocationData[indexPath.row] : weatherListViewData[indexPath.row] + + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapListView)) + cell.addGestureRecognizer(tapGesture) + // 선택 되었을 때 배경색이 바뀌는 것을 방지하기 위한 코드 + let background = UIView() + background.backgroundColor = .clear + cell.selectedBackgroundView = background + cell.bindData(data: dataToDisplay) // 데이터 원본 대신 필터링된 데이터를 전달 + return cell + } +} + + +var filteredLocationData = [WeatherListViewData]() + +extension WeatherListViewController: UISearchResultsUpdating { + var isFiltering: Bool { + let searchController = self.navigationItem.searchController + let isActive = searchController?.isActive ?? false + let isSearchBarHasText = searchController?.searchBar.text?.isEmpty == false + + return isActive && isSearchBarHasText + } + + func updateSearchResults(for searchController: UISearchController) { + guard let text = searchController.searchBar.text else { return } + filteredLocationData = weatherListViewData.filter { return $0.location.lowercased().contains(text.lowercased()) } + self.tableView.reloadData() + } +} diff --git a/assignment1/assignment1/Presentations/WeatherList/WetherListTableViewCell.swift b/assignment1/assignment1/Presentations/WeatherList/WetherListTableViewCell.swift new file mode 100644 index 0000000..59304dc --- /dev/null +++ b/assignment1/assignment1/Presentations/WeatherList/WetherListTableViewCell.swift @@ -0,0 +1,100 @@ +// +// WhetherListTableViewCell.swift +// assignment1 +// +// Created by Seonwoo Kim on 2023/11/06. +// + +import UIKit + +class WetherListTableViewCell: UITableViewCell { + static let identifier: String = "WetherListTableViewCell" + + let backgroundImageView = UIImageView().then { + $0.image = UIImage(named: "listBackground") + $0.contentMode = .scaleAspectFill + } + let myLocationLabel = UILabel().then { + $0.text = "나의 위치" + $0.font = UIFont(name: "SFProDisplay-Bold", size: 24) + $0.textColor = .white + } + let locationLabel = UILabel().then { + $0.font = UIFont(name: "SFProDisplay-Regular", size: 17) + $0.textColor = .white + } + let weatherLabel = UILabel().then { + $0.font = UIFont(name: "SFProDisplay-Regular", size: 16) + $0.textColor = .white + } + let temperatureLabel = UILabel().then { + $0.font = UIFont(name: "SFProDisplay-Light", size: 52) + $0.textColor = .white + } + let maxtemperatureLabel = UILabel().then { + $0.font = UIFont(name: "SFProDisplay-Regular", size: 15) + $0.textColor = .white + } + let mintemperatureLabel = UILabel().then { + $0.font = UIFont(name: "SFProDisplay-Regular", size: 15) + $0.textColor = .white + } + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + self.setLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setLayout() { + self.backgroundColor = .black + + self.isUserInteractionEnabled = true + + self.contentView.addSubview(backgroundImageView) + backgroundImageView.snp.makeConstraints{ + $0.top.equalToSuperview().offset(10) + $0.bottom.equalToSuperview().offset(-10) + $0.leading.trailing.equalToSuperview().inset(20) + } + + [myLocationLabel, locationLabel, weatherLabel, temperatureLabel, maxtemperatureLabel, mintemperatureLabel].forEach { + self.backgroundImageView.addSubview($0) + } + myLocationLabel.snp.makeConstraints { + $0.top.equalToSuperview().inset(10) + $0.leading.equalToSuperview().inset(16) + } + locationLabel.snp.makeConstraints { + $0.top.equalToSuperview().inset(44) + $0.leading.equalToSuperview().inset(16) + } + weatherLabel.snp.makeConstraints { + $0.bottom.equalToSuperview().inset(10) + $0.leading.equalToSuperview().inset(16) + } + temperatureLabel.snp.makeConstraints { + $0.top.equalToSuperview().inset(4) + $0.leading.equalToSuperview().inset(249) + } + maxtemperatureLabel.snp.makeConstraints { + $0.bottom.equalToSuperview().inset(10) + $0.leading.equalToSuperview().inset(196) + } + mintemperatureLabel.snp.makeConstraints { + $0.bottom.equalToSuperview().inset(10) + $0.leading.equalToSuperview().inset(262) + } + } + + func bindData(data: WeatherListViewData) { + self.locationLabel.text = data.location + self.weatherLabel.text = data.weather + self.temperatureLabel.text = data.temperature + self.maxtemperatureLabel.text = data.maxTemperature + self.mintemperatureLabel.text = data.minTemperature + } +}