forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMRReviewerListCell.m
More file actions
131 lines (114 loc) · 4.56 KB
/
MRReviewerListCell.m
File metadata and controls
131 lines (114 loc) · 4.56 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
//
// NSObject+PRReviewerListCell.m
// Coding_iOS
//
// Created by hardac on 16/3/23.
// Copyright © 2016年 Coding. All rights reserved.
//
#import "MRReviewerListCell.h"
#import "Reviewer.h"
#define kDefaultImageSize 33
#define kDefaultImageCount 8
@interface MRReviewerListCell ()
@property (strong, nonatomic) UIImageView *imgView;
@property (strong, nonatomic) NSMutableArray *imgViews;
@property (strong, nonatomic) NSMutableArray *likeHeadImgViews;
@property (strong, nonatomic) UILabel *titleLabel;
@end
@implementation MRReviewerListCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.imgViews = [[NSMutableArray alloc] init];
self.likeHeadImgViews = [[NSMutableArray alloc] init];
self.backgroundColor = kColorTableBG;
for(int i = 0; i < kDefaultImageCount; i ++)
{
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(40 * (i + 1) + 10, 15, kDefaultImageSize, kDefaultImageSize)];
[imgView doCircleFrame];
[imgView setHidden:true];
[self.imgViews addObject:imgView];
[self.contentView addSubview:imgView];
UIImageView *likeHeadView = [[UIImageView alloc] initWithFrame:CGRectMake(40 * (i + 1) + 23,30, 18, 18)];
[likeHeadView doCircleFrame];
[likeHeadView setHidden:true];
[self.likeHeadImgViews addObject:likeHeadView];
[self.contentView addSubview:likeHeadView];
}
}
return self;
}
- (void)prepareForReuse{
[self removeTip];
}
- (void)addTip:(NSString *)countStr{
self.accessoryType = UITableViewCellAccessoryNone;
CGFloat pointX = kScreen_Width - 25;
CGFloat pointY = [[self class] cellHeight]/2;
[self.contentView addBadgeTip:countStr withCenterPosition:CGPointMake(pointX, pointY)];
}
- (void)addTipIcon{
CGFloat pointX = kScreen_Width - 40;
CGFloat pointY = [[self class] cellHeight]/2;
[self.contentView addBadgeTip:kBadgeTipStr withCenterPosition:CGPointMake(pointX, pointY)];
}
- (void)addTipHeadIcon:(NSString *)IconString {
CGFloat pointX = kScreen_Width - 40;
CGFloat pointY = [[self class] cellHeight]/2;
[self.contentView addBadgeTip:IconString withCenterPosition:CGPointMake(pointX, pointY)];
}
- (void)removeTip{
[self.contentView removeBadgeTips];
}
- (void)initCellWithReviewers:(NSArray *)reviewerList{
int imageCount = self.contentView.size.width / 40 - 2;
for(int i = 0; i < kDefaultImageCount; i ++) {
UIImageView *image = self.imgViews[i];
[image setHidden:true];
UIImageView *likeImage = self.likeHeadImgViews[i];
[likeImage setHidden:true];
}
NSMutableArray *dataArray = [[NSMutableArray alloc] initWithArray:reviewerList];
NSArray *reviewers = [dataArray sortedArrayUsingComparator:^NSComparisonResult(Reviewer *obj1, Reviewer *obj2) {
NSComparisonResult result = [ obj2.value compare:obj1.value];
if(result == NSOrderedSame) {
result = [ obj1.volunteer compare:obj2.volunteer];
}
return result;
}];
int index = 0;
for (int i = 0; i < imageCount; i++) {
UIImageView *image = self.imgViews[index];
if(i >= reviewers.count) {
continue;
}
Reviewer* reviewer = (Reviewer*)reviewers[i];
[image setHidden:false];
if(index >= imageCount-1) {
image.image = [UIImage imageNamed:@"PR_more"];
index ++;
continue;
}
[image mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).offset(15);
make.left.equalTo(self.contentView).offset(40 * (index + 1) + 10);
make.bottom.equalTo(self.contentView).offset(-15);
make.right.equalTo(self.contentView).offset(-self.contentView.size.width + (40 * (index + 1) + 10) + 33);
}];
[image sd_setImageWithURL:[reviewer.reviewer.avatar urlImageWithCodePathResizeToView:image] placeholderImage:kPlaceholderMonkeyRoundView(image)];
if([reviewer.volunteer isEqualToString:@"invitee"]) {
if([reviewer.value isEqual:@100]) {
UIImageView *likeImage = self.likeHeadImgViews[index];
[likeImage setHidden:false];
likeImage.image = [UIImage imageNamed:@"PointLikeHead"];
}
}
index ++;
}
}
+ (CGFloat)cellHeight{
return 63.0;
}
@end