-
Notifications
You must be signed in to change notification settings - Fork 0
/
JFThreeStateButton.m
105 lines (78 loc) · 2.34 KB
/
JFThreeStateButton.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
//
// JFThreeStateButton.m
// Tornado
//
// Created by apple on 16/8/29.
// Copyright © 2016年 JunFly. All rights reserved.
//
#import "JFThreeStateButton.h"
@interface JFThreeStateButton ()
@end
@implementation JFThreeStateButton
@synthesize threeState = _threeState;
@synthesize images = _images;
@synthesize titles = _titles;
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (NSMutableArray<UIImage *> *)images {
if (!_images) {
_images = [NSMutableArray arrayWithCapacity:3];
}
return _images;
}
- (NSMutableArray<NSString *> *)titles {
if (!_titles) {
_titles = [NSMutableArray arrayWithCapacity:3];
}
return _titles;
}
- (void)setTitles:(NSMutableArray<NSString *> *)titles {
if (![_titles isEqualToArray:titles]) {
_titles = titles;
[self setContentTitleWithState:self.threeState];
}
}
- (void)setImages:(NSMutableArray<UIImage *> *)images {
if (![_images isEqualToArray:images]) {
_images = images;
[self setContentImageWithState:self.threeState];
}
}
- (void)setThreeState:(JFThreeState)threeState {
if (_threeState != threeState) {
_threeState = threeState;
[self setContentTitleWithState:threeState];
[self setContentImageWithState:threeState];
}
}
- (void)setContentImageWithState:(JFThreeState)threeState {
UIImage *image = nil;
if (self.images.count > threeState) {
image = self.images[threeState];
}
[self setImage:image forState:UIControlStateNormal];
}
- (void)setContentTitleWithState:(JFThreeState)threeState {
NSString *title = nil;
if (self.titles.count > threeState) {
title = self.titles[threeState];
}
[self setTitle:title forState:UIControlStateNormal];
}
//
//- (void)setTitle:(NSString *)title forThreeState:(JFThreeState)state {
// [self setTitle:title forState:UIControlStateNormal];
// [_titles replaceObjectAtIndex:state withObject:title];
//}
//
//- (void)setImage:(UIImage *)image forThreeState:(JFThreeState)state {
// [self setImage:image forState:UIControlStateNormal];
//// self.images[state] = image;
// [self.images replaceObjectAtIndex:state withObject:image];
//}
@end