-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathSplashViewController.swift
More file actions
99 lines (68 loc) · 3.54 KB
/
Copy pathSplashViewController.swift
File metadata and controls
99 lines (68 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import Foundation
import UIKit
public protocol SplashViewControllerDelegate: class {
func splashViewControllerDidTapNewOrder(splashViewController: SplashViewController)
}
public class SplashViewController: UIViewController {
private let services: Services
public weak var delegate: SplashViewControllerDelegate?
private var titleLabel: UILabel = UILabel()
public init(services: Services) {
self.services = services
super.init(nibName: nil, bundle: nil)
}
@available(*, unavailable)
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override public func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
let newOrderButton = UIButton(type: .system)
newOrderButton.setTitle("New order", for: .normal)
newOrderButton.backgroundColor = .red
newOrderButton.addTarget(self, action: #selector(didTapNewOrder), for: UIControl.Event.touchUpInside)
self.view.addSubview(newOrderButton)
newOrderButton.translatesAutoresizingMaskIntoConstraints = false
newOrderButton.widthAnchor.constraint(equalToConstant: 260).isActive = true
newOrderButton.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
newOrderButton.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor, constant: -20).isActive = true
newOrderButton.heightAnchor.constraint(equalToConstant: 44).isActive = true
self.titleLabel.numberOfLines = 0
self.view.addSubview(self.titleLabel)
self.titleLabel.translatesAutoresizingMaskIntoConstraints = false
self.titleLabel.widthAnchor.constraint(equalTo: self.view.widthAnchor).isActive = true
self.titleLabel.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 20).isActive = true
self.updateView()
}
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.updateView()
}
private func updateView() {
let orderCount = self.services.dataService.orders.count
self.titleLabel.attributedText = self.attributedOrderString(orderCount: orderCount)
}
private func attributedOrderString(orderCount: Int) -> NSAttributedString {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
paragraphStyle.lineSpacing = 20
let fontAttributes = [
NSAttributedString.Key.foregroundColor: UIColor.black,
NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 40)
]
let largeFontAttributes = [
NSAttributedString.Key.foregroundColor: UIColor.black,
NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 70)
]
let string = NSMutableAttributedString()
string.append(NSAttributedString(string: "Orders in Progress\n", attributes: fontAttributes))
string.append(NSAttributedString(string: "\(orderCount)", attributes: largeFontAttributes))
return string
}
@objc private func didTapNewOrder(sender: UIButton) {
self.delegate?.splashViewControllerDidTapNewOrder(splashViewController: self)
}
}