forked from dehli/TouchDraw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewController.swift
89 lines (67 loc) · 2.07 KB
/
ViewController.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
//
// ViewController.swift
// TouchDrawDemo
//
// Created by Christian Paul Dehli on 10/4/15.
//
import UIKit
import TouchDraw
class ViewController: UIViewController, TouchDrawViewDelegate {
@IBOutlet var drawView: TouchDrawView!
@IBOutlet weak var undoButton: UIButton!
@IBOutlet weak var redoButton: UIButton!
@IBOutlet weak var clearButton: UIBarButtonItem!
private var deltaWidth = 2.0
override func viewDidLoad() {
super.viewDidLoad()
drawView.delegate = self
drawView.setWidth(CGFloat(deltaWidth))
undoButton.enabled = false
redoButton.enabled = false
clearButton.enabled = false
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func clear(sender: AnyObject) {
drawView.clearDrawing()
}
// Slider can vary from 1 to 10
@IBAction func sliderChanged(sender: UISlider) {
let newWidth = Double(sender.value) * deltaWidth
drawView.setWidth(CGFloat(newWidth))
}
@IBAction func randomColor(sender: AnyObject) {
let r = CGFloat(random() % 255) / 255
let g = CGFloat(random() % 255) / 255
let b = CGFloat(random() % 255) / 255
let color = UIColor(red: r, green: g, blue: b, alpha: 1.0)
drawView.setColor(color)
}
@IBAction func undo(sender: AnyObject) {
drawView.undo()
}
@IBAction func redo(sender: AnyObject) {
drawView.redo()
}
// MARK: - TouchDrawViewDelegate
func undoEnabled() {
self.undoButton.enabled = true
}
func undoDisabled() {
self.undoButton.enabled = false
}
func redoEnabled() {
self.redoButton.enabled = true
}
func redoDisabled() {
self.redoButton.enabled = false
}
func clearEnabled() {
self.clearButton.enabled = true
}
func clearDisabled() {
self.clearButton.enabled = false
}
}