-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRFUICountDownButton.m
105 lines (89 loc) · 1.61 KB
/
RFUICountDownButton.m
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
97
98
99
100
101
102
103
104
105
//
// RFUICountDownButton.h
// RF
//
// Created by gouzhehua on 14-4-18.
// Copyright (c) 2014年 GZH. All rights reserved.
//
#import "RFUICountDownButton.h"
#import "ARCMacros.h"
#import "RFKit.h"
@interface RFUICountDownButton()
{
}
@property (nonatomic, assign) NSInteger progress;
@property (nonatomic, strong) NSTimer *timer;
- (void)timerProc:(NSTimer *)aTime;
@end
@implementation RFUICountDownButton
@synthesize progress;
@synthesize timer;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code
}
return self;
}
- (void)dealloc
{
if (timer != nil)
{
[timer invalidate];
SAFE_ARC_RELEASE(timer);
timer = nil;
}
SAFE_ARC_SUPER_DEALLOC();
}
- (void)setEnabled:(BOOL)enabled
{
[super setEnabled:enabled];
if (enabled)
{
self.alpha = 1.0f;
}
else
{
self.alpha = 0.7f;
}
}
- (void)setEnabled:(BOOL)enabled wait:(NSInteger)full
{
self.enabled = enabled;
if (timer != nil)
{
[timer invalidate];
SAFE_ARC_RELEASE(timer);
timer = nil;
}
if (enabled)
{
}
else
{
progress = full;
[self setTitle:[NSString stringWithInteger:progress] forState:UIControlStateDisabled];
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerProc:) userInfo:nil repeats:YES];
}
}
- (void)timerProc:(NSTimer *)aTime
{
progress--;
if (progress <= 0)
{
if (timer != nil)
{
[timer invalidate];
SAFE_ARC_RELEASE(timer);
timer = nil;
}
[self setEnabled:YES];
}
else
{
[self setTitle:[NSString stringWithInteger:progress] forState:UIControlStateDisabled];
}
}
@end