From 7885dfef1b90a3b5bff2a69abb144857ea6c27e0 Mon Sep 17 00:00:00 2001 From: woongaaaa Date: Thu, 30 Nov 2023 15:40:23 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B3=84=EC=82=B0=EA=B8=B0(=EC=BD=94=EB=93=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOS_Study_B.xcodeproj/project.pbxproj | 49 ++-- .../xcshareddata/swiftpm/Package.resolved | 14 ++ iOS_Study_B/AppDelegate.swift | 4 +- iOS_Study_B/Base.lproj/Main.storyboard | 24 -- iOS_Study_B/Info.plist | 2 - iOS_Study_B/SceneDelegate.swift | 10 +- iOS_Study_B/ViewController.swift | 217 +++++++++++++++++- 7 files changed, 270 insertions(+), 50 deletions(-) create mode 100644 iOS_Study_B.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved delete mode 100644 iOS_Study_B/Base.lproj/Main.storyboard diff --git a/iOS_Study_B.xcodeproj/project.pbxproj b/iOS_Study_B.xcodeproj/project.pbxproj index 9763af9..7b6016f 100644 --- a/iOS_Study_B.xcodeproj/project.pbxproj +++ b/iOS_Study_B.xcodeproj/project.pbxproj @@ -7,10 +7,11 @@ objects = { /* Begin PBXBuildFile section */ + 0907D4B02B186533003820CE /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 0907D4AF2B186533003820CE /* SnapKit */; }; + 0907D4B22B186533003820CE /* SnapKit-Dynamic in Frameworks */ = {isa = PBXBuildFile; productRef = 0907D4B12B186533003820CE /* SnapKit-Dynamic */; }; 954B6B812AC57DAA00FDCFAB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954B6B802AC57DAA00FDCFAB /* AppDelegate.swift */; }; 954B6B832AC57DAA00FDCFAB /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954B6B822AC57DAA00FDCFAB /* SceneDelegate.swift */; }; 954B6B852AC57DAA00FDCFAB /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954B6B842AC57DAA00FDCFAB /* ViewController.swift */; }; - 954B6B882AC57DAA00FDCFAB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B862AC57DAA00FDCFAB /* Main.storyboard */; }; 954B6B8A2AC57DAB00FDCFAB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B892AC57DAB00FDCFAB /* Assets.xcassets */; }; 954B6B8D2AC57DAB00FDCFAB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B8B2AC57DAB00FDCFAB /* LaunchScreen.storyboard */; }; /* End PBXBuildFile section */ @@ -20,7 +21,6 @@ 954B6B802AC57DAA00FDCFAB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 954B6B822AC57DAA00FDCFAB /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 954B6B842AC57DAA00FDCFAB /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 954B6B872AC57DAA00FDCFAB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 954B6B892AC57DAB00FDCFAB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 954B6B8C2AC57DAB00FDCFAB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 954B6B8E2AC57DAB00FDCFAB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -31,6 +31,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 0907D4B02B186533003820CE /* SnapKit in Frameworks */, + 0907D4B22B186533003820CE /* SnapKit-Dynamic in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -59,7 +61,6 @@ 954B6B802AC57DAA00FDCFAB /* AppDelegate.swift */, 954B6B822AC57DAA00FDCFAB /* SceneDelegate.swift */, 954B6B842AC57DAA00FDCFAB /* ViewController.swift */, - 954B6B862AC57DAA00FDCFAB /* Main.storyboard */, 954B6B892AC57DAB00FDCFAB /* Assets.xcassets */, 954B6B8B2AC57DAB00FDCFAB /* LaunchScreen.storyboard */, 954B6B8E2AC57DAB00FDCFAB /* Info.plist */, @@ -83,6 +84,10 @@ dependencies = ( ); name = iOS_Study_B; + packageProductDependencies = ( + 0907D4AF2B186533003820CE /* SnapKit */, + 0907D4B12B186533003820CE /* SnapKit-Dynamic */, + ); productName = iOS_Study_B; productReference = 954B6B7D2AC57DAA00FDCFAB /* iOS_Study_B.app */; productType = "com.apple.product-type.application"; @@ -111,6 +116,9 @@ Base, ); mainGroup = 954B6B742AC57DAA00FDCFAB; + packageReferences = ( + 0907D4AE2B186533003820CE /* XCRemoteSwiftPackageReference "SnapKit" */, + ); productRefGroup = 954B6B7E2AC57DAA00FDCFAB /* Products */; projectDirPath = ""; projectRoot = ""; @@ -127,7 +135,6 @@ files = ( 954B6B8D2AC57DAB00FDCFAB /* LaunchScreen.storyboard in Resources */, 954B6B8A2AC57DAB00FDCFAB /* Assets.xcassets in Resources */, - 954B6B882AC57DAA00FDCFAB /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -147,14 +154,6 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 954B6B862AC57DAA00FDCFAB /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 954B6B872AC57DAA00FDCFAB /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; 954B6B8B2AC57DAB00FDCFAB /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -291,7 +290,6 @@ INFOPLIST_FILE = iOS_Study_B/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 = ( @@ -318,7 +316,6 @@ INFOPLIST_FILE = iOS_Study_B/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 = ( @@ -356,6 +353,30 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 0907D4AE2B186533003820CE /* XCRemoteSwiftPackageReference "SnapKit" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/SnapKit/SnapKit.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 5.6.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 0907D4AF2B186533003820CE /* SnapKit */ = { + isa = XCSwiftPackageProductDependency; + package = 0907D4AE2B186533003820CE /* XCRemoteSwiftPackageReference "SnapKit" */; + productName = SnapKit; + }; + 0907D4B12B186533003820CE /* SnapKit-Dynamic */ = { + isa = XCSwiftPackageProductDependency; + package = 0907D4AE2B186533003820CE /* XCRemoteSwiftPackageReference "SnapKit" */; + productName = "SnapKit-Dynamic"; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 954B6B752AC57DAA00FDCFAB /* Project object */; } diff --git a/iOS_Study_B.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/iOS_Study_B.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..009c162 --- /dev/null +++ b/iOS_Study_B.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,14 @@ +{ + "pins" : [ + { + "identity" : "snapkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/SnapKit/SnapKit.git", + "state" : { + "revision" : "f222cbdf325885926566172f6f5f06af95473158", + "version" : "5.6.0" + } + } + ], + "version" : 2 +} diff --git a/iOS_Study_B/AppDelegate.swift b/iOS_Study_B/AppDelegate.swift index 65a81cc..8c69a28 100644 --- a/iOS_Study_B/AppDelegate.swift +++ b/iOS_Study_B/AppDelegate.swift @@ -1,8 +1,8 @@ // // AppDelegate.swift -// iOS_Study_B +// Calculator // -// Created by 박지윤 on 2023/09/28. +// Created by 황채웅 on 2023/11/08. // import UIKit diff --git a/iOS_Study_B/Base.lproj/Main.storyboard b/iOS_Study_B/Base.lproj/Main.storyboard deleted file mode 100644 index 25a7638..0000000 --- a/iOS_Study_B/Base.lproj/Main.storyboard +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/iOS_Study_B/Info.plist b/iOS_Study_B/Info.plist index dd3c9af..0eb786d 100644 --- a/iOS_Study_B/Info.plist +++ b/iOS_Study_B/Info.plist @@ -15,8 +15,6 @@ Default Configuration UISceneDelegateClassName $(PRODUCT_MODULE_NAME).SceneDelegate - UISceneStoryboardFile - Main diff --git a/iOS_Study_B/SceneDelegate.swift b/iOS_Study_B/SceneDelegate.swift index 9987c27..ebae390 100644 --- a/iOS_Study_B/SceneDelegate.swift +++ b/iOS_Study_B/SceneDelegate.swift @@ -13,10 +13,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { 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 } + guard let windowScene = (scene as? UIWindowScene) else { return } + window = UIWindow(windowScene: windowScene) // SceneDelegate의 프로퍼티에 설정해줌 + let mainViewController = ViewController() // 맨 처음 보여줄 ViewController + + window?.rootViewController = mainViewController + window?.makeKeyAndVisible() } func sceneDidDisconnect(_ scene: UIScene) { diff --git a/iOS_Study_B/ViewController.swift b/iOS_Study_B/ViewController.swift index f3577b5..21b6406 100644 --- a/iOS_Study_B/ViewController.swift +++ b/iOS_Study_B/ViewController.swift @@ -1,19 +1,228 @@ // // ViewController.swift -// iOS_Study_B +// Calculator // -// Created by 박지윤 on 2023/09/28. +// Created by 황채웅 on 2023/11/08. // import UIKit +import SnapKit class ViewController: UIViewController { - + + + let titleLabel: UILabel = { + let label = UILabel() + label.text = "계산기" + label.font = UIFont.systemFont(ofSize: 20, weight: .bold) + label.textColor = .white + + return label + }() + let resultLabel: UILabel = { + let label = UILabel() + label.text = "연산자를 선택해주세요." + label.font = UIFont.systemFont(ofSize: 20) + label.textColor = .white + + return label + }() + let num1TextField: UITextField = { + let textfield = UITextField() + textfield.placeholder = "숫자1 입력" + textfield.font = UIFont.systemFont(ofSize: 20) + textfield.backgroundColor = .white + textfield.keyboardType = .numberPad + textfield.borderStyle = .roundedRect + + return textfield + }() + let num2TextField: UITextField = { + let textfield = UITextField() + textfield.placeholder = "숫자2 입력" + textfield.font = UIFont.systemFont(ofSize: 20) + textfield.backgroundColor = .white + textfield.keyboardType = .numberPad + textfield.borderStyle = .roundedRect + + return textfield + }() + let plusButton: UIButton = { + let button = UIButton() + button.backgroundColor = UIColor(red: 0.91, green: 0.64, blue: 0.24, alpha: 1) + button.layer.cornerRadius = 20 + button.setTitle("+", for: .normal) + button.addTarget(self, action: #selector(plusButtonTapped), for: .touchUpInside) + return button + }() + let minusButton: UIButton = { + let button = UIButton() + button.backgroundColor = UIColor(red: 0.91, green: 0.64, blue: 0.24, alpha: 1) + button.layer.cornerRadius = 20 + button.setTitle("-", for: .normal) + button.addTarget(self, action: #selector(minusButtonTapped), for: .touchUpInside) + return button + }() + let mplButton: UIButton = { + let button = UIButton() + button.backgroundColor = UIColor(red: 0.91, green: 0.64, blue: 0.24, alpha: 1) + button.layer.cornerRadius = 20 + button.setTitle("*", for: .normal) + button.addTarget(self, action: #selector(mplButtonTapped), for: .touchUpInside) + return button + }() + let divButton: UIButton = { + let button = UIButton() + button.backgroundColor = UIColor(red: 0.91, green: 0.64, blue: 0.24, alpha: 1) + button.layer.cornerRadius = 20 + button.setTitle("÷", for: .normal) + button.addTarget(self, action: #selector(divButtonTapped), for: .touchUpInside) + return button + }() + let resetButton: UIButton = { + let button = UIButton() + button.backgroundColor = UIColor(red: 0.91, green: 0.64, blue: 0.24, alpha: 1) + button.layer.cornerRadius = 20 + button.setTitle("초기화", for: .normal) + button.addTarget(self, action: #selector(resetButtonTapped), for: .touchUpInside) + return button + }() + + override func viewDidLoad() { + view.backgroundColor = .black super.viewDidLoad() + configureSubviews() + makeConstraints() // Do any additional setup after loading the view. } + func configureSubviews() { + view.addSubview(titleLabel) + view.addSubview(resultLabel) + view.addSubview(num1TextField) + view.addSubview(num2TextField) + view.addSubview(plusButton) + view.addSubview(minusButton) + view.addSubview(mplButton) + view.addSubview(divButton) + view.addSubview(resetButton) + } + + func makeConstraints() { + titleLabel.snp.makeConstraints { make in + make.centerX.equalToSuperview() + make.top.equalTo(view.safeAreaLayoutGuide).inset(29) + } + resultLabel.snp.makeConstraints { make in + make.centerX.equalToSuperview() + make.top.equalTo(view.safeAreaLayoutGuide).inset(220) + } + num1TextField.snp.makeConstraints { make in + make.top.equalTo(view.safeAreaLayoutGuide).inset(83) + make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(36) + make.height.equalTo(38) + } + num2TextField.snp.makeConstraints { make in + make.top.equalTo(view.safeAreaLayoutGuide).inset(144) + make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(36) + make.height.equalTo(38) + } + plusButton.snp.makeConstraints { make in + make.top.equalTo(view.safeAreaLayoutGuide).inset(288) + make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(36) + make.height.equalTo(45) + } + minusButton.snp.makeConstraints { make in + make.top.equalTo(plusButton.snp.bottom).offset(16) + make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(36) + make.height.equalTo(45) + } + mplButton.snp.makeConstraints { make in + make.top.equalTo(minusButton.snp.bottom).offset(16) + make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(36) + make.height.equalTo(45) + } + divButton.snp.makeConstraints { make in + make.top.equalTo(mplButton.snp.bottom).offset(16) + make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(36) + make.height.equalTo(45) + } + resetButton.snp.makeConstraints { make in + make.top.equalTo(divButton.snp.bottom).offset(16) + make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(36) + make.height.equalTo(45) + } + } + + @objc func plusButtonTapped() { + guard let num1Text = num1TextField.text, !num1Text.isEmpty, + let num2Text = num2TextField.text, !num2Text.isEmpty else { + // 입력값이 하나라도 없을 때 + resultLabel.text = "숫자를 모두 입력해주세요." + return + } + guard let num1 = Int(num1Text), let num2 = Int(num2Text) else { + // 입력값 중 하나라도 숫자가 아닐 때 + resultLabel.text = "숫자만 입력해주세요." + return + } + resultLabel.text = String(num1 + num2) + } + @objc func minusButtonTapped() { + guard let num1Text = num1TextField.text, !num1Text.isEmpty, + let num2Text = num2TextField.text, !num2Text.isEmpty else { + // 입력값이 하나라도 없을 때 + resultLabel.text = "숫자를 모두 입력해주세요." + return + } -} + guard let num1 = Int(num1Text), let num2 = Int(num2Text) else { + // 입력값 중 하나라도 숫자가 아닐 때 + resultLabel.text = "숫자만 입력해주세요." + return + } + resultLabel.text = String(num1 - num2) + } + @objc func mplButtonTapped() { + guard let num1Text = num1TextField.text, !num1Text.isEmpty, + let num2Text = num2TextField.text, !num2Text.isEmpty else { + // 입력값이 하나라도 없을 때 + resultLabel.text = "숫자를 모두 입력해주세요." + return + } + guard let num1 = Int(num1Text), let num2 = Int(num2Text) else { + // 입력값 중 하나라도 숫자가 아닐 때 + resultLabel.text = "숫자만 입력해주세요." + return + } + resultLabel.text = String(num1*num2) + } + @objc func divButtonTapped() { + guard let num1Text = num1TextField.text, !num1Text.isEmpty, + let num2Text = num2TextField.text, !num2Text.isEmpty else { + // 입력값이 하나라도 없을 때 + resultLabel.text = "숫자를 모두 입력해주세요." + return + } + + guard let num1 = Float(num1Text), let num2 = Float(num2Text) else { + // 입력값 중 하나라도 숫자가 아닐 때 + resultLabel.text = "숫자만 입력해주세요." + return + } + if num2==0{ + resultLabel.text = "0으로 나눌 수 없습니다." + }else{ + resultLabel.text = String(num1/num2) + } + } + @objc func resetButtonTapped() { + num1TextField.text = nil + num2TextField.text = nil + resultLabel.text = "연산자를 선택해주세요." + } + + +}