9
9
import UIKit
10
10
11
11
class SFAlertCell : UITableViewCell {
12
+
12
13
static var identifier = " SFAlertCell "
13
14
/// 分割线
14
15
private( set) lazy var separatorView : UIView = {
15
16
$0. translatesAutoresizingMaskIntoConstraints = false
16
17
$0. backgroundColor = UIColor ( red: 0.783922 , green: 0.780392 , blue: 0.8 , alpha: 1 )
17
18
return $0
18
19
} ( UIView ( ) )
19
-
20
+
20
21
private lazy var leftButton : UIButton = {
21
22
$0. setTitleColor ( UIColor ( red: 0 , green: 0.48 , blue: 1 , alpha: 1 ) , for: . selected)
22
23
$0. setTitleColor ( UIColor . black, for: . normal)
@@ -25,7 +26,7 @@ class SFAlertCell: UITableViewCell {
25
26
$0. addTarget ( self , action: #selector( leftButtonTapped) , for: . touchUpInside)
26
27
return $0
27
28
} ( UIButton ( type: . custom) )
28
-
29
+
29
30
private lazy var rightButton : UIButton = {
30
31
$0. isHidden = true
31
32
$0. setTitleColor ( UIColor ( red: 0 , green: 0.48 , blue: 1 , alpha: 1 ) , for: . selected)
@@ -34,10 +35,11 @@ class SFAlertCell: UITableViewCell {
34
35
$0. addTarget ( self , action: #selector( rightButtonTapped) , for: . touchUpInside)
35
36
return $0
36
37
} ( UIButton ( type: . custom) )
37
-
38
+
38
39
var leftCompletion : ( ( ) -> Void ) ?
40
+
39
41
var rightCompletion : ( ( ) -> Void ) ?
40
-
42
+
41
43
/// 内容视图
42
44
private lazy var stackView : UIStackView = {
43
45
$0. translatesAutoresizingMaskIntoConstraints = false
@@ -46,22 +48,26 @@ class SFAlertCell: UITableViewCell {
46
48
$0. axis = . horizontal
47
49
return $0
48
50
} ( UIStackView ( arrangedSubviews: [ leftButton, rightButton] ) )
49
-
51
+
50
52
override init ( style: UITableViewCell . CellStyle , reuseIdentifier: String ? ) {
51
53
super. init ( style: style, reuseIdentifier: reuseIdentifier)
52
54
configSubviews ( )
55
+ configLocation ( )
53
56
}
54
-
57
+
55
58
required init ? ( coder aDecoder: NSCoder ) {
56
59
super. init ( coder: aDecoder)
57
60
configSubviews ( )
61
+ configLocation ( )
58
62
}
59
63
}
60
64
61
65
/// public
62
66
extension SFAlertCell {
63
- func config( using leftButtonType: SFAlertController . AlertButton , rightButtonType: SFAlertController . AlertButton ? = nil ) {
64
-
67
+
68
+ func config( using leftButtonType: SFAlertController . AlertButton ,
69
+ rightButtonType: SFAlertController . AlertButton ? = nil ) {
70
+
65
71
configButton ( leftButton, using: leftButtonType)
66
72
guard let rightButtonType = rightButtonType else {
67
73
separatorView. isHidden = true
@@ -75,12 +81,16 @@ extension SFAlertCell {
75
81
76
82
/// private
77
83
extension SFAlertCell {
78
-
84
+
79
85
private func configSubviews( ) {
80
86
contentView. addSubview ( stackView)
81
87
contentView. addSubview ( separatorView)
82
88
selectionStyle = . none
83
89
contentView. backgroundColor = UIColor ( red: 0.783922 , green: 0.780392 , blue: 0.8 , alpha: 1 )
90
+
91
+ }
92
+
93
+ private func configLocation( ) {
84
94
stackView. topAnchor. constraint ( equalTo: contentView. topAnchor, constant: 0.5 ) . isActive = true
85
95
stackView. leftAnchor. constraint ( equalTo: contentView. leftAnchor) . isActive = true
86
96
stackView. rightAnchor. constraint ( equalTo: contentView. rightAnchor) . isActive = true
@@ -90,6 +100,7 @@ extension SFAlertCell {
90
100
separatorView. centerXAnchor. constraint ( equalTo: contentView. centerXAnchor) . isActive = true
91
101
separatorView. widthAnchor. constraint ( equalToConstant: 0.5 ) . isActive = true
92
102
separatorView. bottomAnchor. constraint ( equalTo: contentView. bottomAnchor) . isActive = true
103
+
93
104
}
94
105
95
106
private func configButton( _ button: UIButton , using type: SFAlertController . AlertButton ) {
0 commit comments