Guest User

Untitled

a guest
Oct 18th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.39 KB | None | 0 0
  1. //UserService.swift
  2. import UIKit
  3. import Alamofire
  4.  
  5.  
  6.  
  7. extension MockData {
  8.  
  9. static func index(completion: @escaping ([MockData]) -> Void) {
  10.  
  11. Alamofire.request("https://www.dropbox.com/s/fem028u5ok95270/Clases.json?dl=1") .responseJSON { (response) in
  12. print(response)
  13. var users = [MockData]()
  14. if let objects = response.result.value {
  15. let json = objects as! NSDictionary
  16. let list = json["Horario"] as? [[String: AnyObject]]
  17.  
  18. for object in list! {
  19. users.append(MockData(dictionary: object))
  20. }
  21. }
  22. completion(users)
  23.  
  24. }
  25.  
  26. }
  27. }
  28.  
  29. //MockData.swift
  30. import UIKit
  31.  
  32. class MockData: NSObject {
  33.  
  34. var id : String?
  35. var dia : DiasClases?
  36. var materia : String?
  37. var horario : String?
  38. var seccion : String?
  39. var profesor : String?
  40. //var aula : String?
  41. //var obs : String?
  42. var HorarioArray = [MockData]()
  43.  
  44.  
  45. init(dictionary: [String: AnyObject]){
  46.  
  47. self.id = dictionary["id"] as? String
  48. let d = dictionary["dia"] as? String
  49. switch d {
  50. case "Lunes"?:
  51. self.dia = .Lunes
  52. case "Martes"?:
  53. self.dia = .Martes
  54. case "Miercoles"?:
  55. self.dia = .Miercoles
  56. case "Jueves"?:
  57. self.dia = .Jueves
  58. case "Viernes"?:
  59. self.dia = .Viernes
  60. case "Sabado"?:
  61. self.dia = .Sabado
  62. default:
  63. print("ERROR")
  64.  
  65. }
  66. self.materia = dictionary["materia"] as? String
  67. self.horario = dictionary["horario"] as? String
  68. self.seccion = dictionary["seccion"] as? String
  69. self.profesor = dictionary["profesor"] as? String
  70. //self.aula = dictionary["aula"] as? String
  71. //self.obs = dictionary["obs"] as? String
  72.  
  73. }
  74.  
  75.  
  76. }
  77.  
  78.  
  79. enum DiasClases {
  80. case Lunes
  81. case Martes
  82. case Miercoles
  83. case Jueves
  84. case Viernes
  85. case Sabado
  86.  
  87. static func AllValues() -> [DiasClases] {
  88. return [Lunes, Martes, Miercoles, Jueves, Viernes, Sabado]
  89. }
  90. }
  91.  
  92. import UIKit
  93.  
  94. class NewsViewController: UIViewController, ACTabScrollViewDelegate, ACTabScrollViewDataSource {
  95.  
  96. @IBOutlet weak var tabScrollView: ACTabScrollView!
  97.  
  98. var contentViews: [UIView] = []
  99. var friends: [MockData] = []
  100.  
  101. override func viewDidLoad() {
  102. super.viewDidLoad()
  103. print("Inicio de viewDidLoad en NewsViewController")
  104. // set ACTabScrollView, all the following properties are optional
  105. tabScrollView.defaultPage = 0
  106. tabScrollView.arrowIndicator = true
  107. tabScrollView.delegate = self
  108. tabScrollView.dataSource = self
  109.  
  110. // crear vistas de contenido de "storyboard"
  111. let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
  112. for category in DiasClases.AllValues() {
  113. let vc = storyboard.instantiateViewController(withIdentifier: "ContentViewController") as! ContentViewController
  114. vc.category = category
  115.  
  116. addChildViewController(vc) // no hay que olvidar, que es muy importante
  117. print("regreso a New")
  118. contentViews.append(vc.view)
  119. print("Termino la funcion viewDidload")
  120.  
  121. }
  122.  
  123. // aspecto de la barra de navegación conjunto
  124. if let navigationBar = self.navigationController?.navigationBar {
  125. print("Dentro del if de conf de barra de navegacion")
  126. navigationBar.isTranslucent = false
  127. navigationBar.tintColor = UIColor.white
  128. navigationBar.barTintColor = UIColor(red: 255.0 / 255, green: 255.0 / 255, blue: 255.0 / 255, alpha: 1)
  129. navigationBar.titleTextAttributes = NSDictionary(object: UIColor.red, forKey: NSForegroundColorAttributeName as NSCopying) as? [String : AnyObject]
  130. navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
  131. navigationBar.shadowImage = UIImage()
  132. }
  133. UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
  134. }
  135.  
  136. // MARK: ACTabScrollViewDelegate
  137. func tabScrollView(_ tabScrollView: ACTabScrollView, didChangePageTo index: Int) {
  138. print(index)
  139. print("cambio de pagina")
  140. }
  141.  
  142. func tabScrollView(_ tabScrollView: ACTabScrollView, didScrollPageTo index: Int) {
  143. print("cambio de pagina con scroll")
  144. }
  145.  
  146. // MARK: ACTabScrollViewDataSource
  147. func numberOfPagesInTabScrollView(_ tabScrollView: ACTabScrollView) -> Int {
  148. print("numeros de paginas")
  149. return DiasClases.AllValues().count
  150. }
  151.  
  152. func tabScrollView(_ tabScrollView: ACTabScrollView, tabViewForPageAtIndex index: Int) -> UIView {
  153. // crear una etiqueta
  154. print("Creando una Etiqueta")
  155. let label = UILabel()
  156. label.text = String(describing: DiasClases.AllValues()[index]).uppercased()
  157. if #available(iOS 8.2, *) {
  158. label.font = UIFont.systemFont(ofSize: 16, weight: UIFontWeightThin)
  159. } else {
  160. label.font = UIFont.systemFont(ofSize: 16)
  161. }
  162. label.textColor = UIColor(red: 255.0 / 255, green: 255.0 / 255, blue: 255.0 / 255, alpha: 1)
  163. label.textAlignment = .center
  164.  
  165. // if the size of your tab is not fixed, you can adjust the size by the following way.
  166. label.sizeToFit() // resize the label to the size of content
  167. label.frame.size = CGSize(width: label.frame.size.width + 28, height: label.frame.size.height + 36) // add some paddings
  168. print("Etiqueta Creada")
  169. return label
  170. }
  171.  
  172. func tabScrollView(_ tabScrollView: ACTabScrollView, contentViewForPageAtIndex index: Int) -> UIView {
  173. print("Dentro de la funcion tabScrollView de NewViewController")
  174. return contentViews[index]
  175. }
  176. }
  177.  
  178. import UIKit
  179.  
  180. class ContentViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  181.  
  182. @IBOutlet weak var tableView: UITableView!
  183.  
  184. var category: DiasClases? {
  185. didSet {
  186. print("Dentro de category")
  187. for news in friends {
  188.  
  189. if (news.dia == category ) {
  190. friends.append(news)
  191. print(friends)
  192. }
  193. }
  194. }
  195. }
  196. var friends: [MockData] = []
  197. override func viewDidLoad() {
  198. super.viewDidLoad()
  199. let refreshControl = UIRefreshControl()
  200. refreshControl.addTarget(self, action:#selector(refresh),for: .valueChanged)
  201. print("Dentro de viewDidLoad en ContentViewController")
  202. tableView.rowHeight = UITableViewAutomaticDimension
  203. tableView.estimatedRowHeight = 44
  204. tableView.delegate = self
  205. tableView.dataSource = self
  206.  
  207. MockData.index { users in
  208. self.friends = users
  209. self.tableView.reloadData()
  210.  
  211. }
  212.  
  213.  
  214.  
  215. print("Fin de viewDidLoad en ContentViewController")
  216. }
  217.  
  218. func numberOfSections(in tableView: UITableView) -> Int {
  219. print("Numero de Secciones de la Tabla")
  220. return 1
  221. }
  222.  
  223. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  224. print("Numero de filas")
  225. return friends.count
  226. }
  227.  
  228. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  229.  
  230. let news = friends[(indexPath as NSIndexPath).row]
  231.  
  232. // set the cell
  233. let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! ContentTableViewCell
  234. //cell.thumbnailImageView.image = UIImage(named: "thumbnail-(news.id)")
  235. //cell.thumbnailImageView.layer.cornerRadius = 4
  236. cell.titleLabel.text = news.materia
  237. cell.categoryLabel.text = String(describing: news.horario!)
  238. cell.categoryView.layer.backgroundColor = UIColor.white.cgColor
  239. cell.categoryView.layer.cornerRadius = 4
  240. cell.categoryView.layer.borderWidth = 1
  241. cell.categoryView.layer.borderColor = UIColor(red: 238.0 / 255, green: 238.0 / 255, blue: 238.0 / 255, alpha: 1.0).cgColor
  242.  
  243. return cell
  244. }
  245.  
  246. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  247. return 0.1
  248. }
  249.  
  250. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  251.  
  252. let view = UIView()
  253. view.backgroundColor = UIColor(red: 0.0 / 255, green: 0.0 / 255, blue: 0.0 / 255, alpha: 1.0)
  254.  
  255. let label = UILabel()
  256. label.text = " "
  257. label.textColor = UIColor.white
  258. if #available(iOS 8.2, *) {
  259. label.font = UIFont.systemFont(ofSize: 17, weight: UIFontWeightThin)
  260. } else {
  261. label.font = UIFont.systemFont(ofSize: 17)
  262. }
  263. label.sizeToFit()
  264. label.frame.origin = CGPoint(x: 18, y: 13)
  265.  
  266. view.addSubview(label)
  267.  
  268. return view
  269. }
  270.  
  271. func refresh() {
  272.  
  273.  
  274.  
  275.  
  276. }
  277.  
  278. }
  279.  
  280. class ContentTableViewCell: UITableViewCell {
  281.  
  282. @IBOutlet weak var thumbnailImageView: UIImageView!
  283. @IBOutlet weak var titleLabel: UILabel!
  284. @IBOutlet weak var categoryView: UIView!
  285. @IBOutlet weak var categoryLabel: UILabel!
  286.  
  287. override func awakeFromNib() {
  288. self.selectionStyle = .none
  289. }
  290.  
  291. }
Add Comment
Please, Sign In to add comment