Skip to content

Commit

Permalink
Merge pull request #4 from IgorChernyshov/feature/add-icon-color
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
kerollesroshdi authored Oct 6, 2020
2 parents 5b262ef + f471ffc commit 5787c22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
20 changes: 7 additions & 13 deletions Sources/KRTabBar/KRTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {

private let customTabBarView: UIView = {
let view = UIView(frame: .zero)
view.backgroundColor = .white
view.layer.cornerRadius = 20
view.backgroundColor = .systemBackground
view.clipsToBounds = true
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()

private let indexView: UIView = {
let view = UIView(frame: .zero)
view.backgroundColor = .orange
view.layer.shadowColor = UIColor.orange.cgColor
view.layer.shadowOpacity = 1
view.layer.shadowOffset = CGSize(width: 2, height: 2)
view.layer.shadowRadius = 10
view.layer.cornerRadius = 20
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
Expand All @@ -55,8 +51,7 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
tabBar.isHidden = true
addcoustmeTabBarView()
tabBar.tintColor = .black
addCustomTabBarView()
createButtonsStack(viewControllers!)
autolayout()
}
Expand All @@ -75,7 +70,8 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {
buttons.removeAll()
buttonsColors.removeAll()

stackView.subviews.forEach {
stackView.arrangedSubviews.forEach {
stackView.removeArrangedSubview($0)
$0.removeFromSuperview()
}

Expand All @@ -84,13 +80,13 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {
assertionFailure("TabBarItems class must be KRTabBarItem")
return
}
buttonsColors.append(tabBarItem.color)
buttonsColors.append(tabBarItem.backgroundColor)

let button = UIButton()
button.tag = index
button.addTarget(self, action: #selector(didSelectIndex(sender:)), for: .touchUpInside)
let image = viewController.tabBarItem.image?.withRenderingMode(.alwaysTemplate)
button.imageView?.tintColor = .black
button.imageView?.tintColor = tabBarItem.iconColor
button.setImage(image, for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
stackView.addArrangedSubview(button)
Expand All @@ -117,7 +113,7 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {
])
}

private func addcoustmeTabBarView() {
private func addCustomTabBarView() {
customTabBarView.frame = tabBar.frame
indexView.frame = tabBar.frame
view.addSubview(customTabBarView)
Expand All @@ -126,10 +122,8 @@ class KRTabBarController: UITabBarController, UITabBarControllerDelegate {

customTabBarView.addSubview(indexView)
customTabBarView.addSubview(stackView)

}


@objc private func didSelectIndex(sender: UIButton) {
let index = sender.tag
self.selectedIndex = index
Expand Down
5 changes: 4 additions & 1 deletion Sources/KRTabBar/KRTabBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ import UIKit

class KRTabBarItem: UITabBarItem {
@IBInspectable
var color: UIColor = UIColor.systemBlue
var backgroundColor: UIColor = UIColor.systemBlue

@IBInspectable
var iconColor: UIColor = .darkText
}

0 comments on commit 5787c22

Please sign in to comment.