Advertisement
1551mats

NetsingTrobles

Feb 27th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 6.53 KB | None | 0 0
  1. //
  2. //  ViewController.swift
  3. //  Asken rooser classes
  4. //
  5. //  Created by Mats Oosterveld on 19/09/15.
  6. //  Copyright © 2015 Mats Oosterveld. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. //MARK: SyestemWide Variables <------------------------------------------------------------------------------> SyestemWide Variables
  12.  
  13. var screenWidth: CGFloat = 0
  14. var screenHeight: CGFloat = 0
  15.  
  16. var hour = screenHeight / 8
  17. var minute = hour / 60
  18.  
  19. var dayWidth: CGFloat = screenWidth
  20.  
  21. let dayBegin = 8.5 //Half past 8 (8 and a half hours past midnight (0))
  22.  
  23. var ItemSizeMon: CGRect = CGRect(x: 0 * dayWidth, y: 0, width: dayWidth, height: 0)
  24. var ItemSizeTue: CGRect = CGRect(x: 1 * dayWidth, y: 0, width: dayWidth, height: 0)
  25. var ItemSizeWed: CGRect = CGRect(x: 2 * dayWidth, y: 0, width: dayWidth, height: 0)
  26. var ItemSizeThu: CGRect = CGRect(x: 3 * dayWidth, y: 0, width: dayWidth, height: 0)
  27. var ItemSizeFri: CGRect = CGRect(x: 4 * dayWidth, y: 0, width: dayWidth, height: 0)
  28.  
  29.  
  30. var TempDidRun = 0
  31.  
  32.  
  33.  
  34. //MARK: ViewController <--------------------------------------------------------------------------------------> ViewController
  35.  
  36.  
  37.  
  38. class ViewController: UIViewController {
  39.  
  40.     override func viewDidLoad() {
  41.         super.viewDidLoad()
  42.        
  43.         print("Viewcontroller")
  44.        
  45.         }
  46.    
  47.     override func didReceiveMemoryWarning() {
  48.         super.didReceiveMemoryWarning()
  49.         // Dispose of any resources that can be recreated.
  50.     }
  51. }
  52.  
  53. //MARK: RoosterViews (the general collection of rooster-subviews) <--------------------------------------------> RoosterViews
  54.  
  55.  
  56.  
  57. class RoosterViews: UIView {
  58.     // Variables
  59.    
  60.     //Initialiation
  61.    
  62.     override func layoutSubviews() {
  63.        
  64.         print("1. Roosterviews")
  65.  
  66.         screenHeight = CGFloat(frame.size.height)
  67.         screenWidth = CGFloat(frame.size.width)
  68.        
  69.         hour = screenHeight / 8
  70.         minute = hour / 60
  71.         dayWidth = screenWidth / 5
  72.        
  73.        
  74.         for i in 1...5 {
  75.            
  76.             let GuideLine = UIView()
  77.             GuideLine.backgroundColor = UIColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1)
  78.             GuideLine.frame = CGRect(x: CGFloat(i) * CGFloat(dayWidth), y: 0, width: 1, height: screenHeight)
  79.             addSubview(GuideLine)
  80.            
  81.            
  82.         }
  83.        
  84.        
  85.        
  86.        
  87.        
  88.         let monday = RoosterViewMonday()
  89.         monday.frame = CGRect(x: 0, y: 0, width: dayWidth, height: screenHeight)
  90.         addSubview(monday)
  91.     }
  92.    
  93.     override init(frame: CGRect) {
  94.         super.init(frame: frame)
  95.     }
  96.    
  97.     required init?(coder aDecoder: NSCoder) {
  98.         super.init(coder: aDecoder)
  99.         // fatalError("init(coder:) has not been implemented")
  100.     }
  101. }
  102.  
  103. //MARK: RoosterViewMonday <-----------------------------------------------------------------------------------> RoosterViewMonday
  104.  
  105.  
  106.  
  107. class RoosterViewMonday: UIView {
  108.    
  109.     override func layoutSubviews() {
  110.        
  111.         print("2. ViewMonday")
  112.  
  113.         let testItem1 = RoosterItem(frame: CGRect(x: 0 * dayWidth, y: 0, width: dayWidth, height: 0))
  114.         testItem1.time = ((10, 15),(0, 40))
  115.         addSubview(testItem1)
  116.        
  117. //        let testItem2 = RoosterItem(frame: CGRect(x: 0 * dayWidth, y: 0, width: dayWidth, height: 0))
  118. //        testItem2.time = ((12, 20),(0, 55))
  119. //        addSubview(testItem2)
  120.        
  121.        
  122.        
  123.     }
  124.    
  125.     override init(frame: CGRect) {
  126.         super.init(frame: frame)
  127.     }
  128.    
  129.     required init?(coder aDecoder: NSCoder) {
  130.         fatalError("init(coder:) has not been implemented")
  131.     }
  132. }
  133.  
  134. //MARK: RoosterItem <-----------------------------------------------------------------------------------------> RoosterItem
  135.  
  136.  
  137. class RoosterItem: UIView {
  138.    
  139.     // Variables
  140.    
  141.     let TimeLblWidth: CGFloat = 45
  142.     let TimeLblHeight: CGFloat = 20
  143.    
  144.     var time = (Start: (StartHour: 0, StartMinute: 0), Duration: (DurationHour: 0, DurationMinute: 0))
  145.    
  146.     var StartPosition: Double = 0
  147.     var StartMinutesInHours: Double = 0
  148.     var DurationMinutesInHours: Double = 0
  149.     var DurationHeight: Double = 0
  150.    
  151.     var tempColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.5)
  152.    
  153.     // Initialation
  154.    
  155.     override func layoutSubviews() {
  156.         if TempDidRun < 20  {
  157.             CalculateTime()
  158.            
  159.             if TempDidRun < 2  {
  160.                 tempColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.2)
  161.             }
  162.             else {
  163.                 tempColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0.2)
  164.             }
  165.            
  166.        
  167.        
  168.         print("3. Roosteritem")
  169.  
  170.         let RoosterCell = UILabel()
  171.         RoosterCell.frame = CGRect(x: 0, y: CGFloat(StartPosition) * hour, width: CGFloat(frame.size.width), height: CGFloat(DurationHeight) * hour)
  172.         RoosterCell.text = "Class"
  173.         RoosterCell.textAlignment = NSTextAlignment.Center
  174.         RoosterCell.backgroundColor = tempColor
  175.         print("did create cell")
  176.         addSubview(RoosterCell)
  177.        
  178.         let TimeLblBegin = UILabel()
  179.         TimeLblBegin.frame = CGRect(x: RoosterCell.frame.minX, y: RoosterCell.frame.minY, width: TimeLblWidth, height: TimeLblHeight)
  180.         TimeLblBegin.text = "\(time.Start.StartHour):\(time.Start.StartMinute)"
  181.         TimeLblBegin.backgroundColor = UIColor(red: 0, green: 0, blue: 1, alpha: 0.2)
  182.         addSubview(TimeLblBegin)
  183.        
  184.         let TimeLblEnd = UILabel()
  185.         TimeLblEnd.frame = CGRect(x: RoosterCell.frame.maxX - TimeLblWidth, y: RoosterCell.frame.maxY - TimeLblHeight, width: TimeLblWidth, height: TimeLblHeight)
  186.         TimeLblEnd.text = "\(time.Start.StartHour + time.Duration.DurationHour):\(time.Start.StartMinute + time.Duration.DurationMinute)"
  187.         TimeLblEnd.backgroundColor = UIColor(red: 0, green: 0, blue: 1, alpha: 0.2)
  188.         addSubview(TimeLblEnd)
  189.         }
  190.     }
  191.    
  192.     func CalculateTime() {
  193.         print("time \(TempDidRun)")
  194.        
  195.         StartMinutesInHours = Double(time.Start.StartMinute) / 60
  196.         StartPosition = Double(time.Start.StartHour) + StartMinutesInHours - dayBegin
  197.        
  198.         DurationMinutesInHours = Double(time.Duration.DurationMinute) / 60
  199.         DurationHeight = Double(time.Duration.DurationHour) + DurationMinutesInHours
  200.         TempDidRun = TempDidRun + 1
  201.     }
  202.    
  203.     override init(frame: CGRect) {
  204.         super.init(frame: frame)
  205.     }
  206.    
  207.     required init?(coder aDecoder: NSCoder) {
  208.         fatalError("init(coder:) has not been implemented")
  209.     }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement