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.

188 lines
4.9 KiB

6 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.barTintColor = Colors.TabBar.barTint
  36. self.tabBar.tintColor = Colors.defaultRed
  37. self.tabBar.isTranslucent = false
  38. self.tabBar.shadowImage = Colors.TabBar.shadow.image()
  39. self.tabBar.backgroundImage = UIImage()
  40. }
  41. override func setupTabItem() {
  42. self.viewControllers?.forEach({ (viewController) in
  43. })
  44. }
  45. }
  46. extension MainViewController: MainViewInterface {
  47. }
  48. extension MainViewController: UITabBarControllerDelegate {
  49. func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
  50. if let nav = viewController as? UINavigationController {
  51. if let _ = nav.viewControllers.first as? RecipientListViewController {
  52. NotificationCenter.default.post(name: Notification.Name.init(AppConstants.MainWireFrameNotificationName), object: nil, userInfo: nil)
  53. return Utility.isVerifiedUser()
  54. }
  55. }
  56. print(tabBarController.selectedIndex)
  57. return true
  58. }
  59. }
  60. //0xec1c24
  61. extension UINavigationBar {
  62. static func setInsideAppearance() {
  63. let navBarAppearance = UINavigationBar.appearance()
  64. navBarAppearance.isTranslucent = false
  65. navBarAppearance.barTintColor = UIColor.white
  66. }
  67. static func setOutsideAppearance() {
  68. self.setInsideAppearance()
  69. let navBarAppearance = UINavigationBar.appearance()
  70. navBarAppearance.barTintColor = Colors.defaultRed
  71. let font = Fonts.NavBar.titleFont
  72. navBarAppearance.titleTextAttributes = [
  73. NSAttributedStringKey.foregroundColor: UIColor.black,
  74. NSAttributedStringKey.font: font]
  75. navBarAppearance.tintColor = UIColor.black
  76. }
  77. static func setupImageAppearance() {
  78. let navBarAppearance = UINavigationBar.appearance()
  79. navBarAppearance.barTintColor = Colors.defaultRed
  80. let font = Fonts.NavBar.titleFont
  81. navBarAppearance.titleTextAttributes = [
  82. NSAttributedStringKey.foregroundColor: UIColor.black,
  83. NSAttributedStringKey.font: font]
  84. navBarAppearance.tintColor = UIColor.black
  85. }
  86. }
  87. @objc protocol Setup {
  88. @objc optional func setupTabItem()
  89. }
  90. extension UIViewController: Setup {
  91. func setupTabItem() {
  92. }
  93. }
  94. struct Colors {
  95. static let separator = UIColor(hex: "#eeeeee")
  96. static let defaultRed = UIColor(hex: "#0xec1c24")
  97. static let cartBadge = UIColor(hex: "#F5951D")
  98. struct TabBar {
  99. static let textItemSelected = Colors.defaultRed
  100. static let textItemNotSelected = UIColor(hex: "#959595")
  101. static let shadow = Colors.separator
  102. }
  103. struct NavBar {
  104. // static let barTint =
  105. static let tint = UIColor.white
  106. static let shadow = Colors.separator
  107. }
  108. struct XLTabBar {
  109. static let titleUnselected = UIColor(hex: "#555555")
  110. static let titleSelected = Colors.defaultRed
  111. static let selectedBackground = Colors.defaultRed
  112. }
  113. }
  114. struct Fonts {
  115. struct Family {
  116. static let regular = "SanFranciscoDisplay-regular"
  117. static let light = "SanFranciscoDisplay-light"
  118. static let bold = "SanFranciscoDisplay-Bold"
  119. static let semiBold = "SanFranciscoDisplay-Semibold"
  120. }
  121. struct TabBar {
  122. static let itemFont = UIFont(name: Family.light, size: 10)!
  123. }
  124. struct NavBar {
  125. static let titleFont = UIFont(name: Family.regular, size: 17)!
  126. }
  127. struct XLTabBar {
  128. static let itemFont = UIFont(name: Family.regular, size: 12)!
  129. }
  130. struct Error {
  131. static let font = UIFont(name: Family.semiBold, size: 11)!
  132. }
  133. }
  134. extension UIColor {
  135. func image(of size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
  136. let rect = CGRect(origin: .zero, size: size)
  137. UIGraphicsBeginImageContextWithOptions(size, false, 0)
  138. self.setFill()
  139. UIRectFill(rect)
  140. let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
  141. UIGraphicsEndImageContext()
  142. return image
  143. }
  144. }