diff --git a/Weather App.xcodeproj/project.pbxproj b/Weather App.xcodeproj/project.pbxproj index e61bb13..12c2926 100644 --- a/Weather App.xcodeproj/project.pbxproj +++ b/Weather App.xcodeproj/project.pbxproj @@ -10,7 +10,6 @@ 7C0D3DB82AFFF60E00688A36 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C0D3DB72AFFF60E00688A36 /* AppDelegate.swift */; }; 7C0D3DBA2AFFF60E00688A36 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C0D3DB92AFFF60E00688A36 /* SceneDelegate.swift */; }; 7C0D3DBC2AFFF60E00688A36 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C0D3DBB2AFFF60E00688A36 /* ViewController.swift */; }; - 7C0D3DBF2AFFF60E00688A36 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7C0D3DBD2AFFF60E00688A36 /* Main.storyboard */; }; 7C0D3DC12AFFF61100688A36 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7C0D3DC02AFFF61100688A36 /* Assets.xcassets */; }; 7C0D3DC42AFFF61100688A36 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7C0D3DC22AFFF61100688A36 /* LaunchScreen.storyboard */; }; /* End PBXBuildFile section */ @@ -20,7 +19,6 @@ 7C0D3DB72AFFF60E00688A36 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7C0D3DB92AFFF60E00688A36 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 7C0D3DBB2AFFF60E00688A36 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 7C0D3DBE2AFFF60E00688A36 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 7C0D3DC02AFFF61100688A36 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 7C0D3DC32AFFF61100688A36 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 7C0D3DC52AFFF61100688A36 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -59,7 +57,6 @@ 7C0D3DB72AFFF60E00688A36 /* AppDelegate.swift */, 7C0D3DB92AFFF60E00688A36 /* SceneDelegate.swift */, 7C0D3DBB2AFFF60E00688A36 /* ViewController.swift */, - 7C0D3DBD2AFFF60E00688A36 /* Main.storyboard */, 7C0D3DC02AFFF61100688A36 /* Assets.xcassets */, 7C0D3DC22AFFF61100688A36 /* LaunchScreen.storyboard */, 7C0D3DC52AFFF61100688A36 /* Info.plist */, @@ -127,7 +124,6 @@ files = ( 7C0D3DC42AFFF61100688A36 /* LaunchScreen.storyboard in Resources */, 7C0D3DC12AFFF61100688A36 /* Assets.xcassets in Resources */, - 7C0D3DBF2AFFF60E00688A36 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -147,14 +143,6 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 7C0D3DBD2AFFF60E00688A36 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 7C0D3DBE2AFFF60E00688A36 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; 7C0D3DC22AFFF61100688A36 /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -299,7 +287,6 @@ INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.weather"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; - INFOPLIST_KEY_UIMainStoryboardFile = Main; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; LD_RUNPATH_SEARCH_PATHS = ( @@ -329,7 +316,6 @@ INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.weather"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; - INFOPLIST_KEY_UIMainStoryboardFile = Main; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; LD_RUNPATH_SEARCH_PATHS = ( diff --git a/Weather App/Info.plist b/Weather App/Info.plist index dd3c9af..0eb786d 100644 --- a/Weather App/Info.plist +++ b/Weather App/Info.plist @@ -15,8 +15,6 @@ Default Configuration UISceneDelegateClassName $(PRODUCT_MODULE_NAME).SceneDelegate - UISceneStoryboardFile - Main diff --git a/Weather App/SceneDelegate.swift b/Weather App/SceneDelegate.swift index 959983e..c102cc0 100644 --- a/Weather App/SceneDelegate.swift +++ b/Weather App/SceneDelegate.swift @@ -16,7 +16,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). - guard let _ = (scene as? UIWindowScene) else { return } + guard let windowScene = (scene as? UIWindowScene) else { return } + window = UIWindow(frame: windowScene.coordinateSpace.bounds) + window?.windowScene = windowScene + window?.rootViewController = ViewController() + window?.makeKeyAndVisible() } func sceneDidDisconnect(_ scene: UIScene) { diff --git a/Weather App/ViewController.swift b/Weather App/ViewController.swift index af0d1ba..1169c6b 100644 --- a/Weather App/ViewController.swift +++ b/Weather App/ViewController.swift @@ -8,10 +8,122 @@ import UIKit class ViewController: UIViewController { + + private lazy var backgroundView: UIImageView = { + let imageView = UIImageView(frame: .zero) + imageView.image = UIImage(named: "background-day") + imageView.contentMode = .scaleAspectFill + imageView.translatesAutoresizingMaskIntoConstraints = false + return imageView + }() + + private lazy var headerView: UIView = { + var view = UIView(frame: .zero) + view.translatesAutoresizingMaskIntoConstraints = false + view.backgroundColor = .white + view.layer.cornerRadius = 20 + return view + }() + + private lazy var cityLabel: UILabel = { + var label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.font = UIFont.systemFont(ofSize: 20) + label.text = "São Paulo" + label.textAlignment = .center + label.textColor = UIColor(.accentColor) + return label + }() + + private lazy var temperatureLabel: UILabel = { + var label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.font = UIFont.systemFont(ofSize: 70,weight: .bold) + label.text = "25˚C" + label.textAlignment = .left + label.textColor = UIColor(.accentColor) + return label + }() + + private lazy var weatherIcon: UIImageView = { + var imageView = UIImageView() + imageView.translatesAutoresizingMaskIntoConstraints = false + imageView.image = UIImage(named: "sunIcon") + imageView.contentMode = .scaleAspectFit + return imageView + }() + + private lazy var humidyLabel: UILabel = { + var label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.font = UIFont.systemFont(ofSize: 12,weight: .semibold) + label.text = "Umidade" + label.textAlignment = .left + label.textColor = UIColor(named: "contrastColor") + return label + }() + + private lazy var humidyValueLabel: UILabel = { + var label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.font = UIFont.systemFont(ofSize: 12,weight: .semibold) + label.text = "1000mm" + label.textAlignment = .left + label.textColor = UIColor(named: "contrastColor") + return label + }() + + private lazy var windLabel: UILabel = { + var label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.font = UIFont.systemFont(ofSize: 12,weight: .semibold) + label.text = "Vento" + label.textAlignment = .left + label.textColor = UIColor(named: "contrastColor") + return label + }() + + private lazy var windValueLabel: UILabel = { + var label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.font = UIFont.systemFont(ofSize: 12,weight: .semibold) + label.text = "10 km/h" + label.textAlignment = .left + label.textColor = UIColor(named: "contrastColor") + return label + }() + + + private lazy var humidityStackView:UIStackView = { + let stackView = UIStackView(arrangedSubviews: [ humidyLabel, humidyValueLabel ]) + stackView.axis = .horizontal + stackView.translatesAutoresizingMaskIntoConstraints = false + return stackView + }() + + private lazy var windStackView:UIStackView = { + let stackView = UIStackView(arrangedSubviews: [ windLabel, windValueLabel ]) + stackView.axis = .horizontal + stackView.translatesAutoresizingMaskIntoConstraints = false + return stackView + }() + + private lazy var statsStackView: UIStackView = { + let marginHorizontal:CGFloat = 24 + let marginVertical:CGFloat = 12 + var stackView = UIStackView(arrangedSubviews: [ humidityStackView, windStackView ] ) + stackView.axis = .vertical + stackView.translatesAutoresizingMaskIntoConstraints = false + stackView.backgroundColor = UIColor(named: "softGray") + stackView.spacing = 3 + stackView.layer.cornerRadius = 10 + stackView.isLayoutMarginsRelativeArrangement = true + stackView.directionalLayoutMargins = NSDirectionalEdgeInsets(top: marginVertical, leading: marginHorizontal, bottom: marginVertical, trailing: marginHorizontal) + return stackView + }() override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view. self.setupView() } @@ -21,11 +133,56 @@ class ViewController: UIViewController { } private func setHierarchy() { - + view.addSubview(backgroundView) + view.addSubview(headerView) + view.addSubview(statsStackView) + headerView.addSubview(cityLabel) + headerView.addSubview(temperatureLabel) + headerView.addSubview(weatherIcon) + humidityStackView.addArrangedSubview(humidyLabel) + humidityStackView.addArrangedSubview(humidyValueLabel) } private func setConstraints (){ + NSLayoutConstraint.activate([ + backgroundView.topAnchor.constraint(equalTo: self.view.topAnchor), + backgroundView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor), + backgroundView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor), + backgroundView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor), + ]) + + NSLayoutConstraint.activate([ + headerView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor,constant: 60), + headerView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor,constant: 35), + headerView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor,constant: -35), + headerView.heightAnchor.constraint(equalToConstant: 169), + ]) + + NSLayoutConstraint.activate([ + cityLabel.topAnchor.constraint(equalTo: headerView.topAnchor, constant: 15), + cityLabel.leadingAnchor.constraint(equalTo: headerView.leadingAnchor, constant: 15), + cityLabel.trailingAnchor.constraint(equalTo: headerView.trailingAnchor, constant: -15), + cityLabel.heightAnchor.constraint(equalToConstant: 20), + ]) + + NSLayoutConstraint.activate([ + temperatureLabel.topAnchor.constraint(equalTo: cityLabel.bottomAnchor, constant: 21), + temperatureLabel.leadingAnchor.constraint(equalTo: headerView.leadingAnchor, constant: 21), + ]) + + NSLayoutConstraint.activate([ + weatherIcon.heightAnchor.constraint(equalToConstant: 86), + weatherIcon.widthAnchor.constraint(equalToConstant: 86), + weatherIcon.trailingAnchor.constraint(equalTo: headerView.trailingAnchor, constant: -21), + weatherIcon.centerYAnchor.constraint(equalTo: temperatureLabel.centerYAnchor,constant: -15), + weatherIcon.leadingAnchor.constraint(equalTo: temperatureLabel.trailingAnchor, constant: 15), + ]) + NSLayoutConstraint.activate([ + statsStackView.topAnchor.constraint(equalTo: headerView.bottomAnchor,constant: 24), + statsStackView.widthAnchor.constraint(equalToConstant: 206), + statsStackView.centerXAnchor.constraint(equalTo: view.centerXAnchor), + ]) } }