-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsViewController.swift
96 lines (68 loc) · 2.82 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
95
96
//
// SettingsViewController.swift
// Tipper
//
// Created by Yang Ruan on 9/29/15.
// Copyright © 2015 Yang Ji. All rights reserved.
//
import UIKit
class SettingsViewController: UIViewController {
@IBOutlet weak var defaultTipControl: UISegmentedControl!
@IBOutlet weak var switchValue: UISwitch!
//Set dark color theme
@IBAction func turnSwitch(sender: UISwitch) {
updateDefaultColor()
}
func updateDefaultColor() {
//save the default color
let defaultDarkSetting = NSUserDefaults.standardUserDefaults()
if switchValue.on {
defaultDarkSetting.setBool(true, forKey: "Default_Dark_Setting")
} else {
defaultDarkSetting.setBool(false, forKey: "Default_Dark_Setting")
}
}
func updateDefaulTip() {
// Save the default tip percentage
let tipDefault = NSUserDefaults.standardUserDefaults()
tipDefault.setInteger(defaultTipControl.selectedSegmentIndex, forKey: "default_tip_segment_index")
tipDefault.synchronize()
}
override func viewDidLoad() {
super.viewDidLoad()
//change the navigationbar tint color
self.navigationController?.navigationBar.tintColor = UIColor(red: 247/255, green: 0, blue: 148/255, alpha: 1)
// Initialize the view with the current default tip percentage
let tipDefault = NSUserDefaults.standardUserDefaults()
let defaultTipSegmentIndex = tipDefault.integerForKey("default_tip_segment_index")
defaultTipControl.selectedSegmentIndex = defaultTipSegmentIndex
//Initialize the swtich with current default switch
let colorDefault = NSUserDefaults.standardUserDefaults()
if colorDefault.boolForKey("Default_Dark_Setting") {
switchValue.setOn(true, animated: false)
} else {
switchValue.setOn(false, animated: false)
}
}
override func viewWillDisappear(animated: Bool) {
updateDefaulTip()
updateDefaultColor()
super.viewWillDisappear(animated)
}
@IBAction func defaultTipControlChange(sender: UISegmentedControl) {
//update default tip control
updateDefaulTip()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}