From c6a2d3adb72fd0a46fde2bec6ab033801acd944c Mon Sep 17 00:00:00 2001 From: eoueono Date: Tue, 15 Apr 2025 03:11:44 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CalculatorApp/ViewController.swift | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CalculatorApp/ViewController.swift b/CalculatorApp/ViewController.swift index 887fe7a..fd28816 100644 --- a/CalculatorApp/ViewController.swift +++ b/CalculatorApp/ViewController.swift @@ -9,11 +9,34 @@ import UIKit class ViewController: UIViewController { + let resultLabel = UILabel() + override func viewDidLoad() { super.viewDidLoad() + view.backgroundColor = .white + setupResultLabel() + setupCalculatorButtons() // Do any additional setup after loading the view. } + func setupResultLabel() { + resultLabel.text = "0" + resultLabel.font = UIFont.systemFont(ofSize: 40) + resultLabel.textAlignment = .right + resultLabel.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(resultLabel) + NSLayoutConstraint.activate([ + resultLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20), + resultLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20), + resultLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), + resultLabel.heightAnchor.constraint(equalToConstant: 80) + ]) + } + + func setupCalculatorButtons() { + + } + } From dda2d75ee07cef82b1905b34c424bbaee8a5c3e8 Mon Sep 17 00:00:00 2001 From: eoueono Date: Tue, 15 Apr 2025 03:28:10 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CalculatorApp/ViewController.swift | 47 +++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/CalculatorApp/ViewController.swift b/CalculatorApp/ViewController.swift index fd28816..4686167 100644 --- a/CalculatorApp/ViewController.swift +++ b/CalculatorApp/ViewController.swift @@ -35,8 +35,53 @@ class ViewController: UIViewController { } func setupCalculatorButtons() { + let buttonTitles = [ + "1", "2", "3", "+", + "4", "5", "6", "-", + "7", "8", "9", "×", + "", "0", "", "÷", + "", "", "", "=" + ] + let stackView = UIStackView() + stackView.axis = .vertical + stackView.spacing = 40 + stackView.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(stackView) + + NSLayoutConstraint.activate([ + stackView.topAnchor.constraint(equalTo: resultLabel.bottomAnchor, constant: 20), + stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), + stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20) + ]) + + var rowStackViews: [UIStackView] = [] + + for (index, title) in buttonTitles.enumerated() { + let button = createButton(withTitle: title) + + if index % 4 == 0 { + let rowStackView = UIStackView() + rowStackView.axis = .horizontal + rowStackView.spacing = 10 + rowStackView.distribution = .fillEqually + rowStackViews.append(rowStackView) + stackView.addArrangedSubview(rowStackView) + } + + rowStackViews[index / 4].addArrangedSubview(button) + } + } + func createButton(withTitle title: String) -> UIButton { + let button = UIButton(type: .system) + button.setTitle(title, for: .normal) + button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside) + return button + } + @objc func buttonTapped(_ sender: UIButton) { + if let title = sender.title(for: .normal) { + print(title) + } } - } From d5834a41cc316febbad5b0a8b5925cd6bc5b77e4 Mon Sep 17 00:00:00 2001 From: eoueono Date: Tue, 15 Apr 2025 03:32:54 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=ED=81=B4=EB=A6=AD=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B2=98=EB=A6=AC=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CalculatorApp/ViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CalculatorApp/ViewController.swift b/CalculatorApp/ViewController.swift index 4686167..7739335 100644 --- a/CalculatorApp/ViewController.swift +++ b/CalculatorApp/ViewController.swift @@ -80,7 +80,7 @@ class ViewController: UIViewController { } @objc func buttonTapped(_ sender: UIButton) { if let title = sender.title(for: .normal) { - print(title) + resultLabel.text = title // 결과레이블에 누른 버튼의 텍스트 출력하기 } } } From 989c4f21ba5729b6ebde3cac6295cd5798bebf38 Mon Sep 17 00:00:00 2001 From: eoueono Date: Tue, 15 Apr 2025 03:38:48 +0900 Subject: [PATCH 4/4] =?UTF-8?q?SceneDelegate=EC=97=90=EC=84=9C=20ViewContr?= =?UTF-8?q?oller=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CalculatorApp/SceneDelegate.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CalculatorApp/SceneDelegate.swift b/CalculatorApp/SceneDelegate.swift index 9e25126..c0a4878 100644 --- a/CalculatorApp/SceneDelegate.swift +++ b/CalculatorApp/SceneDelegate.swift @@ -16,7 +16,12 @@ 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 } + + let window = UIWindow(windowScene: windowScene) + window.rootViewController = ViewController() + self.window = window + window.makeKeyAndVisible() } func sceneDidDisconnect(_ scene: UIScene) {