Last active
June 3, 2018 21:55
-
-
Save iAmrSalman/875ae079e19f478ebe253d752383d195 to your computer and use it in GitHub Desktop.
[Custom TabBar] customizing UITabBarController #tabbar #swift3 #ui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class RootVC: UITabBarController { | |
//MARK: - Propertise | |
let selectedColor = UIColor(red: 238 / 255.0, green: 110 / 255.0, blue: 115 / 255.0, alpha: 1) | |
let unselectedColor = UIColor(red: 37 / 255.0, green: 37 / 255.0, blue: 37 / 255.0, alpha: 1) | |
//MARK: - Life cycle | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let numberOfItems = CGFloat(tabBar.items!.count) | |
let tabBarItemSize = CGSize(width: tabBar.frame.width / numberOfItems, | |
height: tabBar.frame.height) | |
tabBar.selectionIndicatorImage = UIImage.imageWithColor(color: unselectedColor, size: tabBarItemSize).resizableImage(withCapInsets: .zero) | |
tabBar.frame.size.width = self.view.frame.width + 4 | |
tabBar.frame.origin.x = -2 | |
tabBar.barTintColor = UIColor.white | |
tabBar.tintColor = selectedColor | |
UITabBar.appearance().layer.borderWidth = 0.0 | |
UITabBar.appearance().clipsToBounds = true | |
self.view.insertSubview(tabBar.shadowView(color: .black, radius: 3, opacity: 0.2, offset: CGSize(width: 0, height: -2)), belowSubview: tabBar) | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
for item in self.tabBar.items! { | |
item.image = item.selectedImage!.with(color: unselectedColor).withRenderingMode(.alwaysOriginal) | |
item.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment