Files
Woka_Native_iOS/WOKA/TabBar & SideMenu/TabBarVC.swift
Bilal 025aa41585 - Worked on autolayout and did fixes for screen iphone 6s and iphone 11pro max resolutions
- 12-1 woka meeting
- Did Rnd on Container view. This will help for theming
- Made a custom class to add the child view and remove child view.
- Added Moon if the theme color is night
- added the Ca animation for the stars to show glowing effect
- Mapped all the stars with the delay time
- Handled the theme switch
2024-05-24 19:26:54 +05:30

177 lines
6.8 KiB
Swift

// TabBarVC
//
// Created by MacBook Pro on 14/05/24.
//
import UIKit
class TabBarVC: UITabBarController {
var upperLineView: UIView!
let spacing: CGFloat = 12
var customTabBarView = UIView(frame: .zero)
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
customizeTabBarItemFont()
// UITabBar.appearance().tintColor = #colorLiteral(red: 0.0349480696, green: 0.0643344149, blue: 0.4407724142, alpha: 1)
//// UITabBar.appearance().unselectedItemTintColor = #colorLiteral(red: 0.0349480696, green: 0.0643344149, blue: 0.4407724142, alpha: 1)
// UITabBar.appearance().unselectedItemTintColor = #colorLiteral(red: 0.501960814, green: 0.501960814, blue: 0.501960814, alpha: 1)
self.setupTabBarUI()
self.addCustomTabBarView()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if hasTopNotch{
tabBar.frame.size.height = 95
tabBar.frame.origin.y = view.frame.height - 95
}else{
tabBar.frame.size.height = 80
tabBar.frame.origin.y = view.frame.height - 80
}
}
func customizeTabBarItemIconSize() {
// Get a reference to the tab bar controller
if let tabBarController = self.tabBarController {
// Loop through each tab bar item
for item in tabBarController.tabBar.items! {
// Adjust the image insets to increase the icon size
item.imageInsets = UIEdgeInsets(top: 2, left: -5, bottom: -8, right: -5)
item.titlePositionAdjustment.vertical = CGFloat(8)
}
}
}
// function to set tab bar item font
func customizeTabBarItemFont() {
// Set the font attributes
let attributes = [NSAttributedString.Key.font: FontCustom.shareInstance.customFont(fontName: .Exo2_Bold, size: 12)]
// Apply the attributes to the appearance proxy of UITabBarItem
UITabBarItem.appearance().setTitleTextAttributes(attributes, for: .normal)
}
// function to customize tab bar item icon size
// func customizeTabBarItemIconSize() {
// // Get a reference to the tab bar controller
// if let tabBarController = self.tabBarController {
// // Loop through each tab bar item
// for item in tabBarController.tabBar.items! {
// // Adjust the image insets to increase the icon size
// item.imageInsets = UIEdgeInsets(top: 4, left: 0, bottom: -8, right: 0)
// }
// }
// }
///Add tabbar item indicator uper line
// func addTabbarIndicatorView(index: Int, isFirstTime: Bool = false){
// guard let tabView = tabBar.items?[index].value(forKey: "view") as? UIView else {
// return
// }
// if !isFirstTime{
// upperLineView.removeFromSuperview()
// }
// upperLineView = UIView(frame: CGRect(x: tabView.frame.minX + spacing, y: tabView.frame.minY + 0.1, width: tabView.frame.size.width - spacing * 2, height: 4))
// upperLineView.backgroundColor = UIColor.systemPink
// tabBar.addSubview(upperLineView)
// }
// MARK: Private methods
private func setupCustomTabBarFrame() {
let height = self.view.safeAreaInsets.bottom + 64
var tabFrame = self.tabBar.frame
tabFrame.size.height = height
tabFrame.origin.y = self.view.frame.size.height - height
self.tabBar.frame = tabFrame
self.tabBar.setNeedsLayout()
self.tabBar.layoutIfNeeded()
customTabBarView.frame = tabBar.frame
}
private func setupTabBarUI() {
// Setup your colors and corner radius
self.tabBar.backgroundColor = UIColor.white
self.tabBar.layer.cornerRadius = 15
self.tabBar.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
self.tabBar.backgroundColor = .white
self.tabBar.tintColor = #colorLiteral(red: 0.0349480696, green: 0.0643344149, blue: 0.4407724142, alpha: 1)
self.tabBar.unselectedItemTintColor = #colorLiteral(red: 0.501960814, green: 0.501960814, blue: 0.501960814, alpha: 1)
// Remove the line
if #available(iOS 13.0, *) {
let appearance = self.tabBar.standardAppearance
appearance.shadowImage = nil
appearance.shadowColor = nil
self.tabBar.standardAppearance = appearance
} else {
self.tabBar.shadowImage = UIImage()
self.tabBar.backgroundImage = UIImage()
}
}
private func addCustomTabBarView() {
self.customTabBarView.frame = tabBar.frame
self.customTabBarView.backgroundColor = .white
self.customTabBarView.layer.cornerRadius = 30
self.customTabBarView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
self.customTabBarView.layer.masksToBounds = false
self.customTabBarView.layer.shadowColor = UIColor.red.withAlphaComponent(0.8).cgColor
self.customTabBarView.layer.shadowOffset = CGSize(width: -4, height: -6)
self.customTabBarView.layer.shadowOpacity = 0.5
self.customTabBarView.layer.shadowRadius = 20
self.view.addSubview(customTabBarView)
self.view.bringSubviewToFront(self.tabBar)
}
}
extension TabBarVC: UITabBarControllerDelegate {
// Implement the tabBarController(_:didSelect:) method to handle tab changes
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
// This method will be called whenever a tab is selected
// Do something based on the selected index
print("Selected tab index: \(tabBarController.selectedIndex)")
if tabBarController.selectedIndex == 1{
}
}
// Implement the tabBarController(_:shouldSelect:) method to control tab selection
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if viewController == tabBarController.viewControllers?[1] {
let sb = UIStoryboard(name: "Home", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "ExploreWokaVC") as! ExploreWokaVC
vc.modalPresentationStyle = .overCurrentContext
vc.modalTransitionStyle = .crossDissolve
present(vc, animated: true, completion: nil)
return false
}
// Return false to prevent tab selection
return true
}
}
var hasTopNotch: Bool {
if #available(iOS 11.0, tvOS 11.0, *) {
return UIApplication.shared.keyWindowInConnectedScenes?.safeAreaInsets.top ?? 0 > 20
}
return false
}