-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsViewController.swift
94 lines (72 loc) · 2.81 KB
/
SettingsViewController.swift
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// SettingsViewController.swift
// Goal Tracker
//
// Created by Campbell McGavin on 8/8/21.
//
import UIKit
protocol SettingsProtocol{
func settingsChangeDarkMode(_ darkModeOn:Bool)
func settingsChangeTextSize(_ textSize:Int)
}
//*********************************************************************************
// CLASS DEFINITION
//*********************************************************************************
class SettingsViewController: UIViewController {
// MEMBER VARIABLES
var darkModeOn = false
var textSize = 18
var delegate:ViewController?
// IB OUTLETS
@IBOutlet weak var TextStepperOutlet: UIStepper!
@IBOutlet weak var DarkSwitchOutlet: UISwitch!
@IBOutlet weak var FontSizeLabel: UITextField!
// IB ACTIONS
@IBAction func ToggleDarkMode(_ sender: Any) {
// DARK MODE SETTINGS
let darkSwitch = sender as! UISwitch
darkModeOn = darkSwitch.isOn
delegate?.settingsChangeDarkMode(darkModeOn)
UpdateViewDarkMode()
}
@IBAction func ChangeFontSizeAction(_ sender: Any) {
let button = sender as! UIStepper
textSize = Int(button.stepValue)
let tempStr = " pt. font"
let fontSize = CGFloat(TextStepperOutlet.value)
FontSizeLabel.font = FontSizeLabel.font!.withSize(fontSize)
FontSizeLabel.text = String(button.value) + tempStr
delegate?.settingsChangeTextSize(Int(TextStepperOutlet.value))
}
//*********************************************************************************
// VIEW DID LOAD
//*********************************************************************************
override func viewDidLoad() {
super.viewDidLoad()
UpdateViewDarkMode()
TextStepperOutlet.value = Double(textSize)
TextStepperOutlet.maximumValue = 22
TextStepperOutlet.minimumValue = 8
TextStepperOutlet.stepValue = 1
TextStepperOutlet.value = Double(textSize)
UpdateTextSize()
FontSizeLabel.text = String(textSize) + " pt. font"
FontSizeLabel.font = FontSizeLabel.font!.withSize(CGFloat(textSize))
// Do any additional setup after loading the view.
}
//*********************************************************************************
// SETTINGS STUFF
//*********************************************************************************
func UpdateTextSize(){
FontSizeLabel.font = FontSizeLabel.font!.withSize(CGFloat(textSize))
}
func UpdateViewDarkMode(){
DarkSwitchOutlet.isOn = darkModeOn
if darkModeOn{
view.backgroundColor = UIColor.darkGray
}
else{
view.backgroundColor = UIColor.systemBackground
}
}
}