From 7e392d5230ae1d36e5e3553158dc14aa491fac24 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 13 Feb 2025 18:27:20 +0300 Subject: [PATCH 1/5] main functional --- Counter/Base.lproj/Main.storyboard | 43 ++++++++++++++++++++++++++---- Counter/ViewController.swift | 10 +++++-- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Counter/Base.lproj/Main.storyboard b/Counter/Base.lproj/Main.storyboard index 25a7638..6df9e64 100644 --- a/Counter/Base.lproj/Main.storyboard +++ b/Counter/Base.lproj/Main.storyboard @@ -1,24 +1,57 @@ - + + - + + - + - + - + + + + + + + + + + + + + + diff --git a/Counter/ViewController.swift b/Counter/ViewController.swift index fa1cbf6..7c3b648 100644 --- a/Counter/ViewController.swift +++ b/Counter/ViewController.swift @@ -8,12 +8,18 @@ import UIKit class ViewController: UIViewController { - + @IBOutlet weak var counterLabel: UILabel! + private var count: Int = 0 + override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } - + @IBAction func cliickButton() { + count += 1 + counterLabel.text = String(count) + } + } From 1f49e73df734dce7450f6015de94bed7fef7c68c Mon Sep 17 00:00:00 2001 From: = Date: Thu, 13 Feb 2025 22:46:27 +0300 Subject: [PATCH 2/5] full functional --- Counter/Base.lproj/Main.storyboard | 50 ++++++++++++++++++++++++++++-- Counter/ViewController.swift | 34 +++++++++++++++++++- 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/Counter/Base.lproj/Main.storyboard b/Counter/Base.lproj/Main.storyboard index 6df9e64..8c35bfb 100644 --- a/Counter/Base.lproj/Main.storyboard +++ b/Counter/Base.lproj/Main.storyboard @@ -17,7 +17,7 @@ + + + + + + + + + + + + + + + + + + @@ -50,6 +92,10 @@ + + + + diff --git a/Counter/ViewController.swift b/Counter/ViewController.swift index 7c3b648..dfc930a 100644 --- a/Counter/ViewController.swift +++ b/Counter/ViewController.swift @@ -9,6 +9,12 @@ import UIKit class ViewController: UIViewController { @IBOutlet weak var counterLabel: UILabel! + @IBOutlet weak var historyTextView: UITextView! + private var currentData: String { + let formatterDate = DateFormatter() + formatterDate.dateFormat = "dd.MM.YYYY HH:mm" + return formatterDate.string(from: Date()) + } private var count: Int = 0 override func viewDidLoad() { @@ -16,10 +22,36 @@ class ViewController: UIViewController { // Do any additional setup after loading the view. } - @IBAction func cliickButton() { + @IBAction func plusButton() { + //check on max value + guard count != Int.max else { + historyTextView.text += "\n\(currentData) попытка увеличить значение счётчика выше максимума" + return + } + count += 1 counterLabel.text = String(count) + historyTextView.text += "\n\(currentData) значение изменено на +1" + } + + @IBAction func minusButton() { + //check on min value + guard count != 0 else { + historyTextView.text += "\n\(currentData) попытка уменьшить значение счётчика ниже 0" + return + } + + count -= 1 + counterLabel.text = String(count) + historyTextView.text += "\n\(currentData) значение изменено на -1" + } + + @IBAction func resetButton() { + count = 0 + counterLabel.text = String(count) + historyTextView.text += "\n\(currentData) значение сброшено" } } + From bccf367ccbb833942531967f69741c25319e0080 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 14 Feb 2025 15:23:43 +0300 Subject: [PATCH 3/5] add scrool and title --- Counter/Base.lproj/Main.storyboard | 40 ++++++++++++++---------------- Counter/ViewController.swift | 18 ++++++++++---- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Counter/Base.lproj/Main.storyboard b/Counter/Base.lproj/Main.storyboard index 8c35bfb..f1a5cfd 100644 --- a/Counter/Base.lproj/Main.storyboard +++ b/Counter/Base.lproj/Main.storyboard @@ -1,6 +1,6 @@ - + @@ -13,7 +13,7 @@ - + - - - + + - - - - - - - - - + + @@ -88,7 +86,7 @@ - + diff --git a/Counter/ViewController.swift b/Counter/ViewController.swift index dfc930a..792fcfe 100644 --- a/Counter/ViewController.swift +++ b/Counter/ViewController.swift @@ -7,6 +7,13 @@ import UIKit +extension UITextView { + func appendString(text: String) { + self.text += text + self.scrollRangeToVisible(NSRange(location: self.text.count-1, length: 0)) + } +} + class ViewController: UIViewController { @IBOutlet weak var counterLabel: UILabel! @IBOutlet weak var historyTextView: UITextView! @@ -25,33 +32,34 @@ class ViewController: UIViewController { @IBAction func plusButton() { //check on max value guard count != Int.max else { - historyTextView.text += "\n\(currentData) попытка увеличить значение счётчика выше максимума" + historyTextView.appendString(text: "\n\(currentData) попытка увеличить значение счётчика выше максимума\n") return } count += 1 counterLabel.text = String(count) - historyTextView.text += "\n\(currentData) значение изменено на +1" + historyTextView.appendString(text: "\n\(currentData) значение изменено на +1\n") } @IBAction func minusButton() { //check on min value guard count != 0 else { - historyTextView.text += "\n\(currentData) попытка уменьшить значение счётчика ниже 0" + historyTextView.appendString(text: "\n\(currentData) попытка уменьшить значение счётчика ниже 0\n") return } count -= 1 counterLabel.text = String(count) - historyTextView.text += "\n\(currentData) значение изменено на -1" + historyTextView.appendString(text: "\n\(currentData) значение изменено на -1\n") } @IBAction func resetButton() { count = 0 counterLabel.text = String(count) - historyTextView.text += "\n\(currentData) значение сброшено" + historyTextView.appendString(text: "\n\(currentData) значение сброшено\n") } } + From b546936f42ecf7f9f0570fc19ee979271fb13959 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 14 Feb 2025 16:54:25 +0300 Subject: [PATCH 4/5] fix and update history --- Counter/ViewController.swift | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Counter/ViewController.swift b/Counter/ViewController.swift index 792fcfe..d0d731d 100644 --- a/Counter/ViewController.swift +++ b/Counter/ViewController.swift @@ -9,8 +9,7 @@ import UIKit extension UITextView { func appendString(text: String) { - self.text += text - self.scrollRangeToVisible(NSRange(location: self.text.count-1, length: 0)) + self.text = text + self.text } } @@ -26,37 +25,36 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view. } - + @IBAction func plusButton() { //check on max value guard count != Int.max else { - historyTextView.appendString(text: "\n\(currentData) попытка увеличить значение счётчика выше максимума\n") + historyTextView.appendString(text: "\(currentData) попытка увеличить значение счётчика выше максимума\n\n") return } count += 1 counterLabel.text = String(count) - historyTextView.appendString(text: "\n\(currentData) значение изменено на +1\n") + historyTextView.appendString(text: "\(currentData) значение изменено на +1\n\n") } @IBAction func minusButton() { //check on min value guard count != 0 else { - historyTextView.appendString(text: "\n\(currentData) попытка уменьшить значение счётчика ниже 0\n") + historyTextView.appendString(text: "\(currentData) попытка уменьшить значение счётчика ниже 0\n\n") return } count -= 1 counterLabel.text = String(count) - historyTextView.appendString(text: "\n\(currentData) значение изменено на -1\n") + historyTextView.appendString(text: "\(currentData) значение изменено на -1\n\n") } @IBAction func resetButton() { count = 0 counterLabel.text = String(count) - historyTextView.appendString(text: "\n\(currentData) значение сброшено\n") + historyTextView.appendString(text: "\(currentData) значение сброшено\n\n") } } From 3472198ca2ee4225c1e4b982a9cdef7cf8a6fd2c Mon Sep 17 00:00:00 2001 From: = Date: Sat, 15 Feb 2025 09:34:38 +0300 Subject: [PATCH 5/5] final --- Counter/Base.lproj/Main.storyboard | 172 ++++++++++++++++++----------- Counter/ViewController.swift | 12 +- 2 files changed, 117 insertions(+), 67 deletions(-) diff --git a/Counter/Base.lproj/Main.storyboard b/Counter/Base.lproj/Main.storyboard index f1a5cfd..be8d96d 100644 --- a/Counter/Base.lproj/Main.storyboard +++ b/Counter/Base.lproj/Main.storyboard @@ -16,68 +16,116 @@ - - - - - - + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -86,16 +134,16 @@ - + - - - + + + diff --git a/Counter/ViewController.swift b/Counter/ViewController.swift index d0d731d..ce24fe3 100644 --- a/Counter/ViewController.swift +++ b/Counter/ViewController.swift @@ -13,15 +13,20 @@ extension UITextView { } } + class ViewController: UIViewController { @IBOutlet weak var counterLabel: UILabel! @IBOutlet weak var historyTextView: UITextView! private var currentData: String { let formatterDate = DateFormatter() - formatterDate.dateFormat = "dd.MM.YYYY HH:mm" + formatterDate.dateFormat = "[dd.MM.YYYY HH:mm]:" return formatterDate.string(from: Date()) } - private var count: Int = 0 + private var count: Int = 0 { + willSet(newValue) { + counterLabel.text = "Значение счётчика:\n\n\(newValue)" + } + } override func viewDidLoad() { super.viewDidLoad() @@ -35,7 +40,6 @@ class ViewController: UIViewController { } count += 1 - counterLabel.text = String(count) historyTextView.appendString(text: "\(currentData) значение изменено на +1\n\n") } @@ -47,13 +51,11 @@ class ViewController: UIViewController { } count -= 1 - counterLabel.text = String(count) historyTextView.appendString(text: "\(currentData) значение изменено на -1\n\n") } @IBAction func resetButton() { count = 0 - counterLabel.text = String(count) historyTextView.appendString(text: "\(currentData) значение сброшено\n\n") }