-
Notifications
You must be signed in to change notification settings - Fork 363
Expand file tree
/
Copy pathMyEvent.swift
More file actions
73 lines (64 loc) · 1.96 KB
/
MyEvent.swift
File metadata and controls
73 lines (64 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// MyEvent.swift
// CalendarApp
//
// Created by RareScrap on 22.10.2020.
// Copyright © 2020 Richard Topchii. All rights reserved.
//
import Foundation
import CalendarKit
class MyEvent: EventDescriptor {
public var myVar = "asdasd"
public var startDate = Date()
public var endDate = Date()
public var isAllDay = false
public var text = ""
public var attributedText: NSAttributedString?
public var color = SystemColors.systemBlue {
didSet {
updateColors()
}
}
public var backgroundColor = SystemColors.systemBlue.withAlphaComponent(0.3)
public var textColor = SystemColors.label
public var font = UIFont.boldSystemFont(ofSize: 12)
public var userInfo: Any?
public weak var editedEvent: EventDescriptor? {
didSet {
updateColors()
}
}
public init() {}
func makeEditable() -> Self {
let cloned = MyEvent()
cloned.startDate = startDate
cloned.endDate = endDate
cloned.isAllDay = isAllDay
cloned.text = text
cloned.attributedText = attributedText
cloned.color = color
cloned.backgroundColor = backgroundColor
cloned.textColor = textColor
cloned.userInfo = userInfo
cloned.editedEvent = self
return cloned as! Self
}
public func commitEditing() {
guard let edited = editedEvent else {return}
edited.startDate = startDate
edited.endDate = endDate
}
private func updateColors() {
(editedEvent != nil) ? applyEditingColors() : applyStandardColors()
}
private func applyStandardColors() {
backgroundColor = color.withAlphaComponent(0.3)
var h: CGFloat = 0, s: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0
color.getHue(&h, saturation: &s, brightness: &b, alpha: &a)
textColor = UIColor(hue: h, saturation: s, brightness: b * 0.4, alpha: a)
}
private func applyEditingColors() {
backgroundColor = color
textColor = .white
}
}