Skip to content

Commit

Permalink
aula 04
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeCostaAraujo committed Nov 14, 2023
1 parent 417e018 commit 18194bc
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 19 deletions.
14 changes: 0 additions & 14 deletions Weather App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -20,7 +19,6 @@
7C0D3DB72AFFF60E00688A36 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7C0D3DB92AFFF60E00688A36 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
7C0D3DBB2AFFF60E00688A36 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
7C0D3DBE2AFFF60E00688A36 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
7C0D3DC02AFFF61100688A36 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
7C0D3DC32AFFF61100688A36 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
7C0D3DC52AFFF61100688A36 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -127,7 +124,6 @@
files = (
7C0D3DC42AFFF61100688A36 /* LaunchScreen.storyboard in Resources */,
7C0D3DC12AFFF61100688A36 /* Assets.xcassets in Resources */,
7C0D3DBF2AFFF60E00688A36 /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -147,14 +143,6 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
7C0D3DBD2AFFF60E00688A36 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
7C0D3DBE2AFFF60E00688A36 /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
7C0D3DC22AFFF61100688A36 /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 = (
Expand Down
2 changes: 0 additions & 2 deletions Weather App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
Expand Down
6 changes: 5 additions & 1 deletion Weather App/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
161 changes: 159 additions & 2 deletions Weather App/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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),
])
}

}
Expand Down

0 comments on commit 18194bc

Please sign in to comment.