@@ -18,21 +18,17 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {
18
18
19
19
private let customTabBarView : UIView = {
20
20
let view = UIView ( frame: . zero)
21
- view. backgroundColor = . white
22
- view. layer. cornerRadius = 20
21
+ view. backgroundColor = . systemBackground
23
22
view. clipsToBounds = true
24
23
view. translatesAutoresizingMaskIntoConstraints = false
25
24
return view
26
25
} ( )
27
26
28
27
private let indexView : UIView = {
29
28
let view = UIView ( frame: . zero)
30
- view. backgroundColor = . orange
31
- view. layer. shadowColor = UIColor . orange. cgColor
32
29
view. layer. shadowOpacity = 1
33
30
view. layer. shadowOffset = CGSize ( width: 2 , height: 2 )
34
31
view. layer. shadowRadius = 10
35
- view. layer. cornerRadius = 20
36
32
view. translatesAutoresizingMaskIntoConstraints = false
37
33
return view
38
34
} ( )
@@ -55,8 +51,7 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {
55
51
override func viewDidLoad( ) {
56
52
super. viewDidLoad ( )
57
53
tabBar. isHidden = true
58
- addcoustmeTabBarView ( )
59
- tabBar. tintColor = . black
54
+ addCustomTabBarView ( )
60
55
createButtonsStack ( viewControllers!)
61
56
autolayout ( )
62
57
}
@@ -75,7 +70,8 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {
75
70
buttons. removeAll ( )
76
71
buttonsColors. removeAll ( )
77
72
78
- stackView. subviews. forEach {
73
+ stackView. arrangedSubviews. forEach {
74
+ stackView. removeArrangedSubview ( $0)
79
75
$0. removeFromSuperview ( )
80
76
}
81
77
@@ -84,13 +80,13 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {
84
80
assertionFailure ( " TabBarItems class must be KRTabBarItem " )
85
81
return
86
82
}
87
- buttonsColors. append ( tabBarItem. color )
83
+ buttonsColors. append ( tabBarItem. backgroundColor )
88
84
89
85
let button = UIButton ( )
90
86
button. tag = index
91
87
button. addTarget ( self , action: #selector( didSelectIndex ( sender: ) ) , for: . touchUpInside)
92
88
let image = viewController. tabBarItem. image? . withRenderingMode ( . alwaysTemplate)
93
- button. imageView? . tintColor = . black
89
+ button. imageView? . tintColor = tabBarItem . iconColor
94
90
button. setImage ( image, for: . normal)
95
91
button. translatesAutoresizingMaskIntoConstraints = false
96
92
stackView. addArrangedSubview ( button)
@@ -117,7 +113,7 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {
117
113
] )
118
114
}
119
115
120
- private func addcoustmeTabBarView ( ) {
116
+ private func addCustomTabBarView ( ) {
121
117
customTabBarView. frame = tabBar. frame
122
118
indexView. frame = tabBar. frame
123
119
view. addSubview ( customTabBarView)
@@ -126,10 +122,8 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {
126
122
127
123
customTabBarView. addSubview ( indexView)
128
124
customTabBarView. addSubview ( stackView)
129
-
130
125
}
131
126
132
-
133
127
@objc private func didSelectIndex( sender: UIButton ) {
134
128
let index = sender. tag
135
129
self . selectedIndex = index
0 commit comments