Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // Asken rooser classes
- //
- // Created by Mats Oosterveld on 19/09/15.
- // Copyright © 2015 Mats Oosterveld. All rights reserved.
- //
- import UIKit
- //MARK: SyestemWide Variables <------------------------------------------------------------------------------> SyestemWide Variables
- var screenWidth: CGFloat = 0
- var screenHeight: CGFloat = 0
- var hour = screenHeight / 8
- var minute = hour / 60
- var dayWidth: CGFloat = screenWidth
- let dayBegin = 8.5 //Half past 8 (8 and a half hours past midnight (0))
- var ItemSizeMon: CGRect = CGRect(x: 0 * dayWidth, y: 0, width: dayWidth, height: 0)
- var ItemSizeTue: CGRect = CGRect(x: 1 * dayWidth, y: 0, width: dayWidth, height: 0)
- var ItemSizeWed: CGRect = CGRect(x: 2 * dayWidth, y: 0, width: dayWidth, height: 0)
- var ItemSizeThu: CGRect = CGRect(x: 3 * dayWidth, y: 0, width: dayWidth, height: 0)
- var ItemSizeFri: CGRect = CGRect(x: 4 * dayWidth, y: 0, width: dayWidth, height: 0)
- var TempDidRun = 0
- //MARK: ViewController <--------------------------------------------------------------------------------------> ViewController
- class ViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- print("Viewcontroller")
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
- //MARK: RoosterViews (the general collection of rooster-subviews) <--------------------------------------------> RoosterViews
- class RoosterViews: UIView {
- // Variables
- //Initialiation
- override func layoutSubviews() {
- print("1. Roosterviews")
- screenHeight = CGFloat(frame.size.height)
- screenWidth = CGFloat(frame.size.width)
- hour = screenHeight / 8
- minute = hour / 60
- dayWidth = screenWidth / 5
- for i in 1...5 {
- let GuideLine = UIView()
- GuideLine.backgroundColor = UIColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1)
- GuideLine.frame = CGRect(x: CGFloat(i) * CGFloat(dayWidth), y: 0, width: 1, height: screenHeight)
- addSubview(GuideLine)
- }
- let monday = RoosterViewMonday()
- monday.frame = CGRect(x: 0, y: 0, width: dayWidth, height: screenHeight)
- addSubview(monday)
- }
- override init(frame: CGRect) {
- super.init(frame: frame)
- }
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- // fatalError("init(coder:) has not been implemented")
- }
- }
- //MARK: RoosterViewMonday <-----------------------------------------------------------------------------------> RoosterViewMonday
- class RoosterViewMonday: UIView {
- override func layoutSubviews() {
- print("2. ViewMonday")
- let testItem1 = RoosterItem(frame: CGRect(x: 0 * dayWidth, y: 0, width: dayWidth, height: 0))
- testItem1.time = ((10, 15),(0, 40))
- addSubview(testItem1)
- // let testItem2 = RoosterItem(frame: CGRect(x: 0 * dayWidth, y: 0, width: dayWidth, height: 0))
- // testItem2.time = ((12, 20),(0, 55))
- // addSubview(testItem2)
- }
- override init(frame: CGRect) {
- super.init(frame: frame)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
- //MARK: RoosterItem <-----------------------------------------------------------------------------------------> RoosterItem
- class RoosterItem: UIView {
- // Variables
- let TimeLblWidth: CGFloat = 45
- let TimeLblHeight: CGFloat = 20
- var time = (Start: (StartHour: 0, StartMinute: 0), Duration: (DurationHour: 0, DurationMinute: 0))
- var StartPosition: Double = 0
- var StartMinutesInHours: Double = 0
- var DurationMinutesInHours: Double = 0
- var DurationHeight: Double = 0
- var tempColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.5)
- // Initialation
- override func layoutSubviews() {
- if TempDidRun < 20 {
- CalculateTime()
- if TempDidRun < 2 {
- tempColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.2)
- }
- else {
- tempColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0.2)
- }
- print("3. Roosteritem")
- let RoosterCell = UILabel()
- RoosterCell.frame = CGRect(x: 0, y: CGFloat(StartPosition) * hour, width: CGFloat(frame.size.width), height: CGFloat(DurationHeight) * hour)
- RoosterCell.text = "Class"
- RoosterCell.textAlignment = NSTextAlignment.Center
- RoosterCell.backgroundColor = tempColor
- print("did create cell")
- addSubview(RoosterCell)
- let TimeLblBegin = UILabel()
- TimeLblBegin.frame = CGRect(x: RoosterCell.frame.minX, y: RoosterCell.frame.minY, width: TimeLblWidth, height: TimeLblHeight)
- TimeLblBegin.text = "\(time.Start.StartHour):\(time.Start.StartMinute)"
- TimeLblBegin.backgroundColor = UIColor(red: 0, green: 0, blue: 1, alpha: 0.2)
- addSubview(TimeLblBegin)
- let TimeLblEnd = UILabel()
- TimeLblEnd.frame = CGRect(x: RoosterCell.frame.maxX - TimeLblWidth, y: RoosterCell.frame.maxY - TimeLblHeight, width: TimeLblWidth, height: TimeLblHeight)
- TimeLblEnd.text = "\(time.Start.StartHour + time.Duration.DurationHour):\(time.Start.StartMinute + time.Duration.DurationMinute)"
- TimeLblEnd.backgroundColor = UIColor(red: 0, green: 0, blue: 1, alpha: 0.2)
- addSubview(TimeLblEnd)
- }
- }
- func CalculateTime() {
- print("time \(TempDidRun)")
- StartMinutesInHours = Double(time.Start.StartMinute) / 60
- StartPosition = Double(time.Start.StartHour) + StartMinutesInHours - dayBegin
- DurationMinutesInHours = Double(time.Duration.DurationMinute) / 60
- DurationHeight = Double(time.Duration.DurationHour) + DurationMinutesInHours
- TempDidRun = TempDidRun + 1
- }
- override init(frame: CGRect) {
- super.init(frame: frame)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement