-
Notifications
You must be signed in to change notification settings - Fork 3
/
ViewController.swift
50 lines (40 loc) · 1.47 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
//
// ViewController.swift
// MaterialActivityIndicatorView
//
// Created by Tosin Afolabi on 29/11/2014.
// Copyright (c) 2014 Tosin Afolabi. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var indicator: MaterialActivityIndicatorView!
var repeat: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
indicator = MaterialActivityIndicatorView(style: .Large)
indicator.center = view.center
view.addSubview(indicator)
var frame = indicator.frame
frame.origin.y += 100
frame.origin.x = 0
frame.size.width = self.view.frame.size.width
repeat = UIButton(frame: frame)
repeat.setTitle("Repeat", forState: .Normal)
repeat.setTitleColor(UIColor.blackColor(), forState: .Normal)
repeat.setTitleColor(UIColor.lightGrayColor(), forState: .Disabled)
repeat.titleLabel?.font = UIFont(name: "Avenir-Book", size: 20.0)
repeat.titleLabel?.textAlignment = .Center
repeat.addTarget(self, action: "startAnimation", forControlEvents: .TouchUpInside)
view.addSubview(repeat)
startAnimation()
}
func startAnimation() {
repeat!.enabled = false
indicator!.startAnimating()
NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "stopAnimation", userInfo: nil, repeats: false)
}
func stopAnimation() {
repeat!.enabled = true
indicator!.stopAnimating()
}
}