@@ -10,18 +10,20 @@ import Foundation
10
10
import UIKit
11
11
import Splash
12
12
13
- class LayoutDesignerCodePreviewViewController : UIViewController {
13
+ class LayoutDesignerCodePreviewViewController : UIViewController , NibBased , ViewModelBased {
14
14
15
15
// MARK: Properties
16
16
17
- var viewModel : LayoutDesignerCodePreviewViewModel ? {
17
+ var viewModel : LayoutDesignerCodePreviewViewModel ! {
18
18
didSet {
19
19
refreshViews ( )
20
20
}
21
21
}
22
- private weak var codeTextView : UITextView !
23
- private weak var copyButton : UIButton !
24
- private weak var codeModeSegmentedControl : UISegmentedControl !
22
+ @IBOutlet private weak var codeTextView : UITextView !
23
+ @IBOutlet private weak var copyButton : UIButton !
24
+ @IBOutlet private weak var saveButton : UIButton !
25
+ @IBOutlet private weak var helpButton : UIButton !
26
+ @IBOutlet private weak var codeModeSegmentedControl : UISegmentedControl !
25
27
26
28
27
29
// MARK: UIViewController
@@ -34,12 +36,19 @@ class LayoutDesignerCodePreviewViewController: UIViewController {
34
36
35
37
// MARK: Listener
36
38
37
- @objc private func copyButtonTouched( ) {
39
+ @IBAction private func copyButtonTouched( ) {
38
40
let pasteBoard = UIPasteboard . general
39
41
pasteBoard. string = codeTextView. text
40
42
}
41
43
42
- @objc private func codeTypeChanged( ) {
44
+ @IBAction private func saveButtonTouched( ) {
45
+ refreshViews ( )
46
+ }
47
+
48
+ @IBAction private func onHelpButtonTouched( ) {
49
+ }
50
+
51
+ @IBAction private func codeTypeChanged( ) {
43
52
refreshViews ( )
44
53
}
45
54
@@ -48,53 +57,33 @@ class LayoutDesignerCodePreviewViewController: UIViewController {
48
57
49
58
private func configureViews( ) {
50
59
configureTextView ( )
51
- configureCopyButton ( )
60
+ configureButtons ( )
52
61
configureCodeTypeSegmentedControl ( )
53
62
}
54
63
55
- private func configureCopyButton( ) {
56
- let button = UIButton ( )
57
- button. setImage ( UIImage ( named: " copyButton " ) , for: . normal)
58
- button. addTarget ( self , action: #selector( copyButtonTouched) , for: . touchUpInside)
59
- button. translatesAutoresizingMaskIntoConstraints = false
60
- view. addSubview ( button)
61
- copyButton = button
62
- button. topAnchor. constraint ( equalTo: view. topAnchor, constant: 40 ) . isActive = true
63
- button. rightAnchor. constraint ( equalTo: view. rightAnchor, constant: - 25 ) . isActive = true
64
- button. setContentCompressionResistancePriority ( . required, for: . vertical)
64
+ private func configureButtons( ) {
65
+ [ saveButton, copyButton, helpButton] . forEach {
66
+ $0? . layer. cornerRadius = 8
67
+ }
65
68
}
66
69
67
70
private func configureCodeTypeSegmentedControl( ) {
68
- let segmentedControl = UISegmentedControl ( )
69
- segmentedControl. insertSegment ( withTitle: " ViewController " , at: 0 , animated: false )
70
- segmentedControl. insertSegment ( withTitle: " Options variable " , at: 0 , animated: false )
71
- segmentedControl. translatesAutoresizingMaskIntoConstraints = false
72
- view. addSubview ( segmentedControl)
73
- codeModeSegmentedControl = segmentedControl
74
- segmentedControl. topAnchor. constraint ( equalTo: copyButton. topAnchor) . isActive = true
75
- segmentedControl. rightAnchor. constraint ( equalTo: copyButton. leftAnchor, constant: - 10 ) . isActive = true
76
- segmentedControl. leftAnchor. constraint ( greaterThanOrEqualTo: view. leftAnchor, constant: 20 ) . isActive = true
77
- segmentedControl. heightAnchor. constraint ( equalTo: copyButton. heightAnchor) . isActive = true
78
- segmentedControl. backgroundColor = UIColor . black. withAlphaComponent ( 0.4 )
79
- segmentedControl. selectedSegmentTintColor = UIColor . white. withAlphaComponent ( 0.4 )
80
- segmentedControl. setTitleTextAttributes ( [ . foregroundColor: UIColor . white] , for: . normal)
81
- segmentedControl. setTitleTextAttributes ( [ . foregroundColor: UIColor . black. withAlphaComponent ( 0.6 ) ] , for: . selected)
82
- segmentedControl. selectedSegmentIndex = 0
83
- segmentedControl. addTarget ( self , action: #selector( codeTypeChanged) , for: . valueChanged)
71
+ codeModeSegmentedControl. backgroundColor = UIColor . black. withAlphaComponent ( 0.4 )
72
+ codeModeSegmentedControl. selectedSegmentTintColor = UIColor . white. withAlphaComponent ( 0.4 )
73
+ codeModeSegmentedControl. setTitleTextAttributes ( [ . foregroundColor: UIColor . white] , for: . normal)
74
+ codeModeSegmentedControl. setTitleTextAttributes ( [ . foregroundColor: UIColor . black. withAlphaComponent ( 0.6 ) ] , for: . selected)
75
+ codeModeSegmentedControl. selectedSegmentIndex = 0
84
76
85
77
}
86
78
87
79
private func configureTextView( ) {
88
- let codeTextView = UITextView ( )
89
80
codeTextView. backgroundColor = . clear
90
81
codeTextView. isEditable = false
91
- view. fill ( with: codeTextView, edges: . init( top: 100 , left: 20 , bottom: - 20 , right: - 20 ) )
92
- self . codeTextView = codeTextView
93
82
}
94
83
95
84
private func refreshViews( ) {
96
85
codeTextView. attributedText = viewModel? . getHighlightedText (
97
- addViewControllerInCode: codeModeSegmentedControl. selectedSegmentIndex ! = 0
86
+ addViewControllerInCode: codeModeSegmentedControl. selectedSegmentIndex = = 0
98
87
)
99
88
}
100
89
0 commit comments