You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.2 KiB

6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. //
  2. // MainViewController.swift
  3. //
  4. //
  5. // Created by shishir sapkota
  6. //
  7. import Foundation
  8. import UIKit
  9. class MainViewController: UITabBarController {
  10. // MARK: Properties
  11. // MARK: ENUMS:
  12. private enum Items: Int {
  13. case home = 0
  14. case sendMoney
  15. case branch
  16. case profile
  17. }
  18. var presenter: MainModuleInterface?
  19. // MARK: VC's Life cycle
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22. self.delegate = self
  23. self.setupAppearance()
  24. }
  25. func setup(viewControllers: [UIViewController]) {
  26. self.viewControllers = viewControllers
  27. self.setupTab()
  28. setupTabItem()
  29. }
  30. // MARK: Other functions
  31. func setupAppearance() {
  32. UINavigationBar.setInsideAppearance()
  33. }
  34. private func setupTab() {
  35. self.tabBar.tintColor = Colors.defaultRed
  36. self.tabBar.isTranslucent = false
  37. self.tabBar.shadowImage = Colors.TabBar.shadow.image()
  38. self.tabBar.backgroundImage = UIImage()
  39. // self.tabBar.barTintColor = .themeMainBackground
  40. }
  41. override func setupTabItem() {
  42. }
  43. }
  44. extension MainViewController: MainViewInterface {
  45. }
  46. extension MainViewController: UITabBarControllerDelegate {
  47. func tabBarController(
  48. _ tabBarController: UITabBarController,
  49. shouldSelect viewController: UIViewController
  50. ) -> Bool {
  51. if let nav = viewController as? UINavigationController {
  52. if nav.viewControllers.first as? RecipientsViewController != nil {
  53. NotificationCenter.default.post(
  54. name: Notification.Name.init(AppConstants.MainWireFrameNotificationName),
  55. object: nil,
  56. userInfo: nil
  57. )
  58. return Utility.isVerifiedUser()
  59. }
  60. }
  61. print(tabBarController.selectedIndex)
  62. return true
  63. }
  64. }
  65. extension UINavigationBar {
  66. static func setInsideAppearance() {
  67. let navBarAppearance = UINavigationBar.appearance()
  68. navBarAppearance.isTranslucent = false
  69. navBarAppearance.barTintColor = UIColor.white
  70. }
  71. static func setOutsideAppearance() {
  72. self.setInsideAppearance()
  73. let navBarAppearance = UINavigationBar.appearance()
  74. navBarAppearance.barTintColor = Colors.defaultRed
  75. let font = Fonts.NavBar.titleFont
  76. navBarAppearance.titleTextAttributes = [
  77. NSAttributedString.Key.foregroundColor: UIColor.black,
  78. NSAttributedString.Key.font: font]
  79. navBarAppearance.tintColor = UIColor.black
  80. }
  81. static func setupImageAppearance() {
  82. let navBarAppearance = UINavigationBar.appearance()
  83. navBarAppearance.barTintColor = Colors.defaultRed
  84. let font = Fonts.NavBar.titleFont
  85. navBarAppearance.titleTextAttributes = [
  86. NSAttributedString.Key.foregroundColor: UIColor.black,
  87. NSAttributedString.Key.font: font]
  88. navBarAppearance.tintColor = UIColor.black
  89. }
  90. }
  91. @objc protocol Setup {
  92. @objc optional func setupTabItem()
  93. }
  94. extension UIViewController: Setup {
  95. func setupTabItem() {
  96. }
  97. }
  98. struct Colors {
  99. static let separator = UIColor(hex: "#eeeeee")
  100. static let defaultRed = UIColor(hex: "#0xec1c24")
  101. static let cartBadge = UIColor(hex: "#F5951D")
  102. struct TabBar {
  103. static let textItemSelected = Colors.defaultRed
  104. static let textItemNotSelected = UIColor(hex: "#959595")
  105. static let shadow = Colors.separator
  106. }
  107. struct NavBar {
  108. // static let barTint =
  109. static let tint = UIColor.white
  110. static let shadow = Colors.separator
  111. }
  112. struct XLTabBar {
  113. static let titleUnselected = UIColor(hex: "#555555")
  114. static let titleSelected = Colors.defaultRed
  115. static let selectedBackground = Colors.defaultRed
  116. }
  117. }
  118. struct Fonts {
  119. struct TabBar {
  120. static let itemFont = UIFont.sanfrancisco(.light, size: 10)
  121. }
  122. struct NavBar {
  123. static let titleFont = UIFont.sanfrancisco(.regular, size: 17)
  124. }
  125. struct XLTabBar {
  126. static let itemFont = UIFont.sanfrancisco(.regular, size: 12)
  127. }
  128. struct Error {
  129. static let font = UIFont.sanfrancisco(.semibold, size: 11)
  130. }
  131. }
  132. extension UIColor {
  133. func image(of size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
  134. let rect = CGRect(origin: .zero, size: size)
  135. UIGraphicsBeginImageContextWithOptions(size, false, 0)
  136. self.setFill()
  137. UIRectFill(rect)
  138. let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
  139. UIGraphicsEndImageContext()
  140. return image
  141. }
  142. }