This commit is contained in:
Михаил Капелько
2023-05-01 18:15:33 +03:00
parent 041cdc0dea
commit 6612cfcbd2
8 changed files with 67 additions and 51 deletions

View File

@@ -11,7 +11,7 @@ extension AppDelegate {
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = Main.VC()
window?.rootViewController = Main.Core()
window?.makeKeyAndVisible()
return true

View File

@@ -1,7 +1,9 @@
import UIKit
// MARK: - Ядро-VC
extension Main {
class VC: UIViewController {
class Core: UIViewController {
var buttons = [UIButton]()
override func viewDidLoad() {
@@ -10,6 +12,7 @@ extension Main {
view.backgroundColor = .white
Main.Section16Buttons.setupCore(self)
Main.SectionGrid.setupCore(self)
}
}
}

View File

@@ -0,0 +1,21 @@
import UIKit
// MARK: - Протоколы
protocol MainSection16Buttons { }
// MARK: - Реализация
extension Main {
enum Section16Buttons {
static func setupCore(_ core: Main.Core) {
// Создаём 16 кнопок.
for i in 0..<16 {
let btn = UIButton()
btn.tag = i
core.view.addSubview(btn)
core.buttons.append(btn)
}
}
}
}

View File

@@ -0,0 +1,25 @@
import UIKit
// MARK: - Протоколы
protocol MainSectionGrid { }
// MARK: - Реализация
extension Main {
enum SectionGrid {
static func setupCore(_ core: Main.Core) {
let side = 50
let space = 20
let gap = side + space
// Расставляем кнопки в сетке 4x4.
for btn in core.buttons {
let id = btn.tag
let row = Int(id / 4)
btn.frame = CGRect(x: gap + (id - row * 4) * gap, y: gap + row * gap, width: side, height: side)
btn.backgroundColor = .blue
}
}
}
}

View File

@@ -1,29 +0,0 @@
import UIKit
// MARK: - Протоколы
protocol MainSection16Buttons {
}
// MARK: - Реализация
extension Main {
enum Section16Buttons {
static func setupCore(_ core: Main.VC) {
// Создаём 16 кнопок.
for i in 0..<16 {
let btn = UIButton()
core.buttons.append(btn)
btn.tag = i
//????btn.addTarget(self, action: #selector(selectButton), for: .touchUpInside)
core.view.addSubview(btn)
}
// Расставляем их в сетке 4x4.
for btn in core.buttons {
btn.frame = CGRect(x: 0, y: btn.tag * 60, width: 50, height: 50)
btn.backgroundColor = .blue
}
}
}
}