CNLiveMonthBillView.m
8.54 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//
// CNLiveMonthBillView.m
// CNLiveBalanceModule
//
// Created by 153993236@qq.com on 11/12/2019.
// Copyright © 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveMonthBillView.h"
#import "QMUIKit.h"
#import <Masonry/Masonry.h>
#import "CNLiveCategory.h"
#import "CNLiveBaseKit.h"
#import "PGDatePickManager.h"
#import "CNLiveBalanceRequest.h"
@interface CNLiveMonthBillView ()<PGDatePickerDelegate>
@property (nonatomic, strong) QMUIButton *switchTime;
@property (nonatomic, strong) UIButton *defray;//收入
@property (nonatomic, strong) UIButton *income;//支出
@property (nonatomic, strong) UIView *defrayLine;
@property (nonatomic, strong) UIView *incomeLine;
@end
@implementation CNLiveMonthBillView
static const NSInteger margin = 20;
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
self.userInteractionEnabled = YES;
self.backgroundColor = [UIColor clearColor];
[self createSubViews];
}
return self;
}
- (void)createSubViews {
[self addSubview:self.switchTime];
[self addSubview:self.defray];
[self addSubview:self.income];
[self addSubview:self.defrayLine];
[self addSubview:self.incomeLine];
[_defray mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.mas_right).with.offset(-margin);
make.centerY.equalTo(self.mas_centerY);
make.width.height.offset(40);
}];
[_defrayLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.centerX.equalTo(_defray);
make.width.mas_equalTo(15);
make.height.mas_equalTo(3);
}];
[_income mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.defray.mas_left).with.offset(-margin);
make.centerY.equalTo(self.mas_centerY);
make.width.height.offset(40);
}];
[_incomeLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.centerX.equalTo(_income);
make.width.mas_equalTo(15);
make.height.mas_equalTo(3);
}];
[_switchTime mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_top).with.offset(0);
make.left.equalTo(self.mas_left).with.offset(margin);
make.width.offset(120);
make.height.offset(self.height);
}];
_incomeLine.hidden = NO;
_defrayLine.hidden = YES;
}
- (void)setDate:(NSString *)date{
_date = date;
[_switchTime setTitle:date forState:UIControlStateNormal];
}
#pragma mark - PGDatePickerDelegate
- (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents{
dateComponents.day = 1;
NSCalendar * calendar = [NSCalendar currentCalendar];
NSDate *date = [calendar dateFromComponents:dateComponents];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setDateFormat:@"yyyy年M月"];
NSString *value = [dateFormatter stringFromDate:date];
[_switchTime setTitle:value forState:UIControlStateNormal];
NSArray *times = [CNLiveBalanceRequest getMonthFirstAndLastDayWithDate:date];
NSLog(@"%@",times);
if (self.delegate && [self.delegate respondsToSelector:@selector(monthBillView:startTime:endTime:)]) {
[self.delegate monthBillView:self startTime:times.firstObject endTime:times.lastObject];
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
#pragma mark - 响应方法
- (void)switchTimeDidClicked:(UIButton *)btn{
PGDatePickManager *datePickManager = [[PGDatePickManager alloc] init];
datePickManager.style = PGDatePickManagerStyleSheet;
datePickManager.isShadeBackground = true;
datePickManager.cancelButtonTextColor = RGB(136, 136, 136);
datePickManager.confirmButtonTextColor = RGB(33, 188, 35);
PGDatePicker *datePicker = datePickManager.datePicker;
datePicker.isHiddenMiddleText = false;
datePicker.delegate = self;
datePicker.datePickerType = PGDatePickerTypeLine;
datePicker.datePickerMode = PGDatePickerModeYearAndMonth;
datePicker.lineBackgroundColor = RGB(232, 232, 232);
datePicker.textColorOfSelectedRow = KBlack51Color;
datePicker.textColorOfOtherRow = RGB(169, 169, 169);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
dateFormatter.dateFormat = @"yyyy年MM月";
//获取当前时间日期
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
datePicker.minimumDate = [dateFormatter dateFromString:@"2017年1月"];
datePicker.maximumDate = [dateFormatter dateFromString:dateString];
[(UIViewController *)self.delegate presentViewController:datePickManager animated:NO completion:nil];
}
- (void)setInteractionEnabled:(BOOL)interactionEnabled{
_interactionEnabled = interactionEnabled;
_defray.userInteractionEnabled = interactionEnabled;
_income.userInteractionEnabled = interactionEnabled;
}
- (void)btnDidClicked:(UIButton *)btn{
if (self.delegate && [self.delegate respondsToSelector:@selector(switchType:)]) {
btn.userInteractionEnabled = NO;
if(btn.tag == 10000){//收入
[self.delegate switchType:@"1"];
_defray.selected = YES;
_defrayLine.hidden = NO;
_income.selected = NO;
_incomeLine.hidden = YES;
}else if (btn.tag == 10001){//支出
[self.delegate switchType:@"2"];
_income.selected = YES;
_incomeLine.hidden = NO;
_defray.selected = NO;
_defrayLine.hidden = YES;
}
}
}
#pragma mark - 懒加载
- (QMUIButton *)switchTime {
if (!_switchTime) {
_switchTime = [QMUIButton buttonWithType:UIButtonTypeCustom];
_switchTime.adjustsImageWhenHighlighted = NO;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy年M月"];
NSString *dateTime = [formatter stringFromDate:[NSDate date]];
[_switchTime setTitle:dateTime forState:UIControlStateNormal];
[_switchTime setTitleColor:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0] forState:UIControlStateNormal];
_switchTime.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
UIImage *xw_image = [self getImageWithImageName:@"record_switch_time" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
[_switchTime setImage:[xw_image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
_switchTime.titleLabel.font = UIFontCNMake(17);
[_switchTime addTarget:self action:@selector(switchTimeDidClicked:) forControlEvents:UIControlEventTouchUpInside];
_switchTime.imagePosition = QMUIButtonImagePositionRight;
_switchTime.spacingBetweenImageAndTitle = 8;
}
return _switchTime;
}
- (UIButton *)defray {
if (!_defray) {
_defray = [UIButton buttonWithType:UIButtonTypeCustom];
_defray.adjustsImageWhenHighlighted = NO;
_defray.tag = 10000;
_defray.titleLabel.font = [UIFont systemFontOfSize:14.0];
[_defray setTitle:@"收入" forState:UIControlStateNormal];
[_defray setTitleColor:RGB(58, 58, 58) forState:UIControlStateNormal];
[_defray setTitleColor:RGB(11, 190, 6) forState:UIControlStateSelected];
[_defray addTarget:self action:@selector(btnDidClicked:) forControlEvents:UIControlEventTouchUpInside];
}
return _defray;
}
- (UIButton *)income {
if (!_income) {
_income = [UIButton buttonWithType:UIButtonTypeCustom];
_income.adjustsImageWhenHighlighted = NO;
_income.tag = 10001;
_income.titleLabel.font = [UIFont systemFontOfSize:14.0];
[_income setTitle:@"支出" forState:UIControlStateNormal];
[_income setTitleColor:RGB(58, 58, 58) forState:UIControlStateNormal];
[_income setTitleColor:RGB(11, 190, 6) forState:UIControlStateSelected];
[_income addTarget:self action:@selector(btnDidClicked:) forControlEvents:UIControlEventTouchUpInside];
_income.selected = YES;
}
return _income;
}
- (UIView *)defrayLine{
if (!_defrayLine) {
_defrayLine = [[UIView alloc] init];
_defrayLine.backgroundColor = RGB(11, 190, 6);
}
return _defrayLine;
}
- (UIView *)incomeLine{
if (!_incomeLine) {
_incomeLine = [[UIView alloc] init];
_incomeLine.backgroundColor = RGB(11, 190, 6);
}
return _incomeLine;
}
@end