forked from lexrus/LTMorphingLabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LTDemoViewController.swift
96 lines (80 loc) · 2.71 KB
/
LTDemoViewController.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
//
// LTDemoViewController.swift
// LTMorphingLabelDemo
//
// Created by Lex on 6/23/14.
// Copyright (c) 2015 LexTang.com. All rights reserved.
//
import UIKit
class LTDemoViewController: UIViewController, LTMorphingLabelDelegate {
var i = 0
var textArray = [
"What is design?",
"Design", "Design is not just", "what it looks like", "and feels like.",
"Design", "is how it works.", "- Steve Jobs",
"Older people", "sit down and ask,", "'What is it?'",
"but the boy asks,", "'What can I do with it?'.", "- Steve Jobs",
"", "Swift", "Objective-C", "iPhone", "iPad", "Mac Mini", "MacBook Pro", "Mac Pro",
"爱老婆",
"老婆和女儿"]
var text:String {
get {
if i >= textArray.count {
i = 0
}
return textArray[i++]
}
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
self.label.delegate = self
}
@IBOutlet var label: LTMorphingLabel!
@IBAction func changeText(sender: AnyObject) {
label.text = text
}
@IBAction func segmentChanged(sender: UISegmentedControl) {
let seg = sender
switch seg.selectedSegmentIndex {
case 1:
self.label.morphingEffect = .Evaporate
case 2:
self.label.morphingEffect = .Fall
case 3:
self.label.morphingEffect = .Pixelate
case 4:
self.label.morphingEffect = .Sparkle
case 5:
self.label.morphingEffect = .Burn
case 6:
self.label.morphingEffect = .Anvil
default:
self.label.morphingEffect = .Scale
}
self.changeText(sender);
}
@IBAction func toggleLight(sender: UISegmentedControl) {
let isNight = Bool(sender.selectedSegmentIndex == 0)
self.view.backgroundColor = isNight ? UIColor.blackColor() : UIColor.whiteColor()
self.label.textColor = isNight ? UIColor.whiteColor() : UIColor.blackColor()
}
@IBAction func changeFontSize(sender: UISlider) {
self.label.font = self.label.font.fontWithSize(CGFloat(sender.value))
self.label.text = self.label.text
self.label.setNeedsDisplay()
}
}
extension LTDemoViewController {
func morphingDidStart(label: LTMorphingLabel) {
// println("\(label) did start morphing.")
}
func morphingDidComplete(label: LTMorphingLabel) {
// println("\(label) did complete morphing.")
}
func morphingOnProgress(label: LTMorphingLabel, _ progress: Float) {
// println("\(label) is morphing on progress: \(progress)")
}
}