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
//
// InspectHeaderView.m
// redstar
//
// Created by admin on 15/11/12.
// Copyright © 2015年 ZWF. All rights reserved.
//
#import "InspectHeaderView.h"
#import "TaskGroup.h"
@interface InspectHeaderView ()
{
UIButton *_bgButton;
UIImageView *_arrowImageView;
UIView *_lineView;
}
@end
@implementation InspectHeaderView
+ (instancetype)headViewWithTableView:(UITableView *)tableView
{
static NSString *headIdentifier = @"header";
InspectHeaderView *headView = (InspectHeaderView *)[tableView dequeueReusableCellWithIdentifier:headIdentifier];
if (headView == nil) {
headView = [[InspectHeaderView alloc] initWithReuseIdentifier:headIdentifier];
}
return headView;
}
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
UIButton *bgButton = [UIButton buttonWithType:UIButtonTypeCustom];
bgButton.backgroundColor = [UIColor whiteColor];
bgButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
bgButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
bgButton.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
[bgButton addTarget:self action:@selector(headBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:bgButton];
_bgButton = bgButton;
UIImageView *arrowIMView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_down"]];
[self addSubview:arrowIMView];
_arrowImageView = arrowIMView;
UIView *lineView = [[UIView alloc] init];
lineView.backgroundColor = kSeparateLineColor;
[self addSubview:lineView];
_lineView = lineView;
}
return self;
}
- (void)headBtnClick
{
_taskGroup.opened = !_taskGroup.isOpened;
if ([_delegate respondsToSelector:@selector(clickHeadView)]) {
[_delegate clickHeadView];
}
}
- (void)setTaskGroup:(TaskGroup *)taskGroup
{
_taskGroup = taskGroup;
NSString *nameStr = [NSString stringWithFormat:@"模块 -- %@(10/%lu)", taskGroup.name, (unsigned long)taskGroup.classfiy.count];
NSMutableAttributedString *nameAttr = [[NSMutableAttributedString alloc] initWithString:nameStr];
[nameAttr addAttributes:@{NSForegroundColorAttributeName:kLightBlack,NSFontAttributeName:[UIFont systemFontOfSize:17.0f]} range:NSMakeRange(0,nameStr.length)];
[_bgButton setAttributedTitle:nameAttr forState:UIControlStateNormal];
}
- (void)didMoveToSuperview
{
_arrowImageView.transform = _taskGroup.isOpened ? CGAffineTransformMakeRotation(M_PI) : CGAffineTransformMakeRotation(0);
_lineView.hidden = _taskGroup.isOpened ? YES : NO;
}
- (void)layoutSubviews
{
[super layoutSubviews];
_bgButton.frame = self.bounds;
_arrowImageView.frame = CGRectMake(self.frame.size.width - 33, (self.frame.size.height - 8) / 2, 13, 8);
_lineView.frame = CGRectMake(0, self.frame.size.height - 1, self.frame.size.width, 1);
}
@end