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.

199 lines
5.5 KiB

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