diff --git a/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR.xcodeproj/project.pbxproj b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR.xcodeproj/project.pbxproj index b32d6e9..a7105c9 100644 --- a/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR.xcodeproj/project.pbxproj +++ b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR.xcodeproj/project.pbxproj @@ -10,9 +10,10 @@ 7EB7B90329DF4A3600C2A7F6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EB7B90229DF4A3600C2A7F6 /* AppDelegate.swift */; }; 7EB7B90529DF4A3600C2A7F6 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EB7B90429DF4A3600C2A7F6 /* SceneDelegate.swift */; }; 7EB7B90729DF4A3600C2A7F6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EB7B90629DF4A3600C2A7F6 /* ViewController.swift */; }; - 7EB7B90A29DF4A3600C2A7F6 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7EB7B90829DF4A3600C2A7F6 /* Main.storyboard */; }; 7EB7B90C29DF4A3A00C2A7F6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7EB7B90B29DF4A3A00C2A7F6 /* Assets.xcassets */; }; 7EB7B90F29DF4A3A00C2A7F6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7EB7B90D29DF4A3A00C2A7F6 /* LaunchScreen.storyboard */; }; + 7EB7B91729DF54D300C2A7F6 /* NewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EB7B91629DF54D300C2A7F6 /* NewViewController.swift */; }; + 7EB7B91929DF564F00C2A7F6 /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EB7B91829DF564F00C2A7F6 /* SecondViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -20,10 +21,11 @@ 7EB7B90229DF4A3600C2A7F6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7EB7B90429DF4A3600C2A7F6 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 7EB7B90629DF4A3600C2A7F6 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 7EB7B90929DF4A3600C2A7F6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 7EB7B90B29DF4A3A00C2A7F6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 7EB7B90E29DF4A3A00C2A7F6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 7EB7B91029DF4A3A00C2A7F6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 7EB7B91629DF54D300C2A7F6 /* NewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewViewController.swift; sourceTree = ""; }; + 7EB7B91829DF564F00C2A7F6 /* SecondViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -59,10 +61,11 @@ 7EB7B90229DF4A3600C2A7F6 /* AppDelegate.swift */, 7EB7B90429DF4A3600C2A7F6 /* SceneDelegate.swift */, 7EB7B90629DF4A3600C2A7F6 /* ViewController.swift */, - 7EB7B90829DF4A3600C2A7F6 /* Main.storyboard */, 7EB7B90B29DF4A3A00C2A7F6 /* Assets.xcassets */, 7EB7B90D29DF4A3A00C2A7F6 /* LaunchScreen.storyboard */, 7EB7B91029DF4A3A00C2A7F6 /* Info.plist */, + 7EB7B91629DF54D300C2A7F6 /* NewViewController.swift */, + 7EB7B91829DF564F00C2A7F6 /* SecondViewController.swift */, ); path = "GO-SOPT-FIRST-SEMINAR"; sourceTree = ""; @@ -127,7 +130,6 @@ files = ( 7EB7B90F29DF4A3A00C2A7F6 /* LaunchScreen.storyboard in Resources */, 7EB7B90C29DF4A3A00C2A7F6 /* Assets.xcassets in Resources */, - 7EB7B90A29DF4A3600C2A7F6 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -141,20 +143,14 @@ 7EB7B90729DF4A3600C2A7F6 /* ViewController.swift in Sources */, 7EB7B90329DF4A3600C2A7F6 /* AppDelegate.swift in Sources */, 7EB7B90529DF4A3600C2A7F6 /* SceneDelegate.swift in Sources */, + 7EB7B91929DF564F00C2A7F6 /* SecondViewController.swift in Sources */, + 7EB7B91729DF54D300C2A7F6 /* NewViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 7EB7B90829DF4A3600C2A7F6 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 7EB7B90929DF4A3600C2A7F6 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; 7EB7B90D29DF4A3A00C2A7F6 /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -292,7 +288,6 @@ INFOPLIST_FILE = "GO-SOPT-FIRST-SEMINAR/Info.plist"; 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 = ( @@ -320,7 +315,6 @@ INFOPLIST_FILE = "GO-SOPT-FIRST-SEMINAR/Info.plist"; 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/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/Info.plist b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/Info.plist index dd3c9af..0eb786d 100644 --- a/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/Info.plist +++ b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/Info.plist @@ -15,8 +15,6 @@ Default Configuration UISceneDelegateClassName $(PRODUCT_MODULE_NAME).SceneDelegate - UISceneStoryboardFile - Main diff --git a/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/NewViewController.swift b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/NewViewController.swift new file mode 100644 index 0000000..f80c94b --- /dev/null +++ b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/NewViewController.swift @@ -0,0 +1,161 @@ +// +// NewViewController.swift +// GO-SOPT-FIRST-SEMINAR +// +// Created by 김사랑 on 2023/04/07. +// + +import UIKit + +class NewViewController: UIViewController { + + private let nameLabel: UILabel = { + let label = UILabel() + label.text = "이름이 무엇인가요🥸" + label.font = .boldSystemFont(ofSize: 20) + label.textColor = .black + label.textAlignment = .center + return label + }() + + private let valueSlider: UISlider = { + let slider = UISlider() + slider.minimumValue = 0 + slider.maximumValue = 100 + slider.value = 50 + slider.minimumTrackTintColor = .black + return slider + }() + + private lazy var presentButton: UIButton = { + let button = UIButton() + button.setTitle("present", for: .normal) + button.backgroundColor = .black + button.layer.cornerRadius = 10 + button.layer.shadowColor = UIColor.black.cgColor + button.layer.shadowOpacity = 0.4 //투명도 + button.layer.shadowOffset = CGSize.zero //위치 + button.layer.shadowRadius = 7 //반경 + + button.setTitleColor(.white, for: .normal) + + button.addTarget(self, + action: #selector(presentButtonTapped), + for: .touchUpInside) + + return button + }() + + private lazy var pushButton: UIButton = { + let button = UIButton() + button.setTitle("push", for: .normal) + button.backgroundColor = .black + button.layer.cornerRadius = 10 + button.layer.shadowColor = UIColor.black.cgColor + button.layer.shadowOpacity = 0.4 //투명도 + button.layer.shadowOffset = CGSize.zero //위치 + button.layer.shadowRadius = 7 //반경 + button.setTitleColor(.white, for: .normal) + + button.addTarget(self, + action: #selector(pushButtonTapped), + for: .touchUpInside) + + return button + }() + + private let nameTextField: UITextField = { + let textField = UITextField() + textField.placeholder = "이름을 적어주세요 :)" + textField.clearButtonMode = .whileEditing + textField.layer.borderColor = UIColor.black.cgColor + textField.layer.cornerRadius = 10 + textField.layer.borderWidth = 0.1 + textField.leftView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 15.0, height: 0.0)) //여백주기 + textField.leftViewMode = .always + + return textField + }() + + override func viewDidLoad() { + super.viewDidLoad() + + style() + setLayout() + // Do any additional setup after loading the view. + } + + + +} + +private extension NewViewController { + + func style() { + + view.backgroundColor = .white + } + + func setLayout() { + + [nameLabel, nameTextField, + presentButton, pushButton, valueSlider].forEach { + $0.translatesAutoresizingMaskIntoConstraints = false + view.addSubview($0) + } + + NSLayoutConstraint.activate([nameLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: 300), + nameLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30), + nameLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30)]) + + NSLayoutConstraint.activate([valueSlider.topAnchor.constraint(equalTo: nameLabel.bottomAnchor, constant: 10), + valueSlider.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30), + valueSlider.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30)]) + + NSLayoutConstraint.activate([nameTextField.topAnchor.constraint(equalTo: valueSlider.bottomAnchor, constant: 10), + nameTextField.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30), + nameTextField.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30), + nameTextField.heightAnchor.constraint(equalToConstant: 48)]) + + NSLayoutConstraint.activate([presentButton.topAnchor.constraint(equalTo: nameTextField.bottomAnchor, constant: 20), + presentButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30), + presentButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30), + presentButton.heightAnchor.constraint(equalToConstant: 48)]) + + NSLayoutConstraint.activate([pushButton.topAnchor.constraint(equalTo: presentButton.bottomAnchor, constant: 20), + pushButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30), + pushButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30), + pushButton.heightAnchor.constraint(equalToConstant: 48)]) + } + + func presentToSecondViewController() { + + let secondViewController = SecondViewController_1st_Seminar() + secondViewController.modalPresentationStyle = .fullScreen + self.present(secondViewController, animated: true) + } + + func pushToSecondViewController() { + + let secondViewController = SecondViewController_1st_Seminar() + if let name = nameTextField.text{ + secondViewController.dataBind(name: name) + } + self.navigationController?.pushViewController(secondViewController, animated: true) + } + + @objc + func presentButtonTapped() { + + presentToSecondViewController() + } + + @objc + func pushButtonTapped() { + + pushToSecondViewController() + } + + + +} diff --git a/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/SceneDelegate.swift b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/SceneDelegate.swift index 07c0a25..b20083d 100644 --- a/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/SceneDelegate.swift +++ b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/SceneDelegate.swift @@ -8,45 +8,19 @@ import UIKit class SceneDelegate: UIResponder, UIWindowSceneDelegate { - + var window: UIWindow? - - + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { - // 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 } - } - - func sceneDidDisconnect(_ scene: UIScene) { - // Called as the scene is being released by the system. - // This occurs shortly after the scene enters the background, or when its session is discarded. - // Release any resources associated with this scene that can be re-created the next time the scene connects. - // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). - } - - func sceneDidBecomeActive(_ scene: UIScene) { - // Called when the scene has moved from an inactive state to an active state. - // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. - } - - func sceneWillResignActive(_ scene: UIScene) { - // Called when the scene will move from an active state to an inactive state. - // This may occur due to temporary interruptions (ex. an incoming phone call). - } - - func sceneWillEnterForeground(_ scene: UIScene) { - // Called as the scene transitions from the background to the foreground. - // Use this method to undo the changes made on entering the background. - } - - func sceneDidEnterBackground(_ scene: UIScene) { - // Called as the scene transitions from the foreground to the background. - // Use this method to save data, release shared resources, and store enough scene-specific state information - // to restore the scene back to its current state. + + // 1. + guard let windowScene = (scene as? UIWindowScene) else { return } + // 2. + self.window = UIWindow(windowScene: windowScene) + // 3. + let navigationController = UINavigationController(rootViewController: NewViewController()) + self.window?.rootViewController = navigationController + // 4. + self.window?.makeKeyAndVisible() } - - } - diff --git a/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/SecondViewController.swift b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/SecondViewController.swift new file mode 100644 index 0000000..fcbf9f2 --- /dev/null +++ b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/SecondViewController.swift @@ -0,0 +1,83 @@ +// +// SecondViewController.swift +// GO-SOPT-FIRST-SEMINAR +// +// Created by 김사랑 on 2023/04/07. +// + +import UIKit + +final class SecondViewController_1st_Seminar: UIViewController { + + private let nameLabel: UILabel = { + let label = UILabel() + label.text = "반가워요!" + label.font = .boldSystemFont(ofSize: 20) + return label + }() + + private lazy var backButton: UIButton = { + let button = UIButton() + button.setTitle("뒤로가기", for: .normal) + button.setTitleColor(.blue, for: .normal) + button.titleLabel?.font = .boldSystemFont(ofSize: 20) + + button.addTarget(self, + action: #selector(backButtonTapped), + for: .touchUpInside) + + return button + }() + + override func viewDidLoad() { + super.viewDidLoad() + + style() + setLayout() + + } + + func dataBind(name: String) { + nameLabel.text = name + } + + +} + +private extension SecondViewController_1st_Seminar { + + func style() { + + view.backgroundColor = .white + } + + func setLayout() { + + [nameLabel, backButton].forEach { + $0.translatesAutoresizingMaskIntoConstraints = false + view.addSubview($0) + } + + NSLayoutConstraint.activate([nameLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor), + nameLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor)]) + + + NSLayoutConstraint.activate([backButton.topAnchor.constraint(equalTo: nameLabel.bottomAnchor, constant: 20), + backButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30), + backButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30), + backButton.heightAnchor.constraint(equalToConstant: 48)]) + } + + @objc + func backButtonTapped() { + + if self.navigationController == nil { + self.dismiss(animated: true, completion: nil) + } else { + self.navigationController?.popViewController(animated: true) + } + } + + + +} diff --git a/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/ViewController.swift b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/ViewController.swift index a5c1d6f..8bf88dd 100644 --- a/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/ViewController.swift +++ b/GO-SOPT-FIRST-SEMINAR/GO-SOPT-FIRST-SEMINAR/ViewController.swift @@ -7,13 +7,36 @@ import UIKit -class ViewController: UIViewController { +final class ViewController: UIViewController { + + private let nameLabel: UILabel = { + let label = UILabel() + label.text = "솝트에 오신 여러분 환영합니다!" + return label + }() override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view. - } - + setStyle() + setLayout() + } } +private extension ViewController { + + func setStyle() { + + view.backgroundColor = .white + } + + func setLayout() { + + nameLabel.translatesAutoresizingMaskIntoConstraints = false + + view.addSubview(nameLabel) + + NSLayoutConstraint.activate([nameLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: 300), + nameLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 50)]) + } +}