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.

174 lines
4.7 KiB

  1. //
  2. // MainViewController.swift
  3. // Sipradi
  4. //
  5. // Created by bibek timalsina on 5/26/17.
  6. // Copyright © 2017 Ekbana. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. class MainViewController: UITabBarController {
  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.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. viewController.tabBarItem.imageInsets = UIEdgeInsets(top: 7, left: 0, bottom: -7, right: 0)
  44. })
  45. }
  46. }
  47. extension MainViewController: MainViewInterface {
  48. }
  49. //0xec1c24
  50. extension UINavigationBar {
  51. static func setInsideAppearance() {
  52. let navBarAppearance = UINavigationBar.appearance()
  53. navBarAppearance.isTranslucent = false
  54. navBarAppearance.barTintColor = UIColor.white
  55. // navBarAppearance.shadowImage = UIImage() //Colors.NavBar.shadow.image()
  56. // let font = Fonts.NavBar.titleFont
  57. //
  58. // navBarAppearance.titleTextAttributes = [
  59. // NSAttributedStringKey.foregroundColor: Colors.NavBar.tint,
  60. // NSAttributedStringKey.font: font]
  61. // navBarAppearance.tintColor = Colors.NavBar.tint
  62. }
  63. static func setOutsideAppearance() {
  64. self.setInsideAppearance()
  65. let navBarAppearance = UINavigationBar.appearance()
  66. navBarAppearance.barTintColor = Colors.defaultRed
  67. let font = Fonts.NavBar.titleFont
  68. navBarAppearance.titleTextAttributes = [
  69. NSAttributedStringKey.foregroundColor: UIColor.black,
  70. NSAttributedStringKey.font: font]
  71. navBarAppearance.tintColor = UIColor.black
  72. }
  73. static func setupImageAppearance() {
  74. // self.setInsideAppearance()
  75. let navBarAppearance = UINavigationBar.appearance()
  76. navBarAppearance.barTintColor = Colors.defaultRed
  77. let font = Fonts.NavBar.titleFont
  78. navBarAppearance.titleTextAttributes = [
  79. NSAttributedStringKey.foregroundColor: UIColor.black,
  80. NSAttributedStringKey.font: font]
  81. navBarAppearance.tintColor = UIColor.black
  82. }
  83. }
  84. @objc protocol Setup {
  85. @objc optional func setupTabItem()
  86. }
  87. extension UIViewController: Setup {
  88. func setupTabItem() {
  89. }
  90. }
  91. struct Colors {
  92. static let separator = UIColor(hex: "#eeeeee")
  93. static let defaultRed = UIColor(hex: "#0xec1c24")
  94. static let cartBadge = UIColor(hex: "#F5951D")
  95. struct TabBar {
  96. static let textItemSelected = Colors.defaultRed
  97. static let textItemNotSelected = UIColor(hex: "#959595")
  98. static let shadow = Colors.separator
  99. }
  100. struct NavBar {
  101. // static let barTint =
  102. static let tint = UIColor.white
  103. static let shadow = Colors.separator
  104. }
  105. struct XLTabBar {
  106. static let titleUnselected = UIColor(hex: "#555555")
  107. static let titleSelected = Colors.defaultRed
  108. static let selectedBackground = Colors.defaultRed
  109. }
  110. }
  111. struct Fonts {
  112. private struct Family {
  113. static let regular = "SanFranciscoDisplay-regular"
  114. static let light = "SanFranciscoDisplay-light"
  115. static let bold = "SanFranciscoDisplay-Bold"
  116. }
  117. struct TabBar {
  118. static let itemFont = UIFont(name: Family.light, size: 10)!
  119. }
  120. struct NavBar {
  121. static let titleFont = UIFont(name: Family.regular, size: 17)!
  122. }
  123. struct XLTabBar {
  124. static let itemFont = UIFont(name: Family.light, size: 12)!
  125. }
  126. }
  127. extension UIColor {
  128. func image(of size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
  129. let rect = CGRect(origin: .zero, size: size)
  130. UIGraphicsBeginImageContextWithOptions(size, false, 0)
  131. self.setFill()
  132. UIRectFill(rect)
  133. let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
  134. UIGraphicsEndImageContext()
  135. return image
  136. }
  137. }