forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectItemsCell.m
More file actions
133 lines (109 loc) · 5.25 KB
/
ProjectItemsCell.m
File metadata and controls
133 lines (109 loc) · 5.25 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
//
// ProjectItemsCell.m
// Coding_iOS
//
// Created by Ease on 15/3/12.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#define ProjectItemsCell_ItemHeight (kScreen_Width/4)
#define ProjectItemsCell_PadingHeight kScaleFrom_iPhone5_Desgin(10)
#import "ProjectItemsCell.h"
#import <FontAwesome+iOS/UIImage+FontAwesome.h>
@interface ProjectItemsCell ()
@property (strong, nonatomic) NSMutableArray *items;
@end
@implementation ProjectItemsCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
NSInteger itemsNum = 0, itemsNumInLine = 1;
NSArray *itemsIconList, *itemsColorList, *itemsTitleList;
if ([reuseIdentifier isEqualToString:kCellIdentifier_ProjectItemsCell_Private]) {
itemsNum = 6;
itemsNumInLine = 3;
itemsIconList = @[@"icon-bolt", @"icon-tasks", @"icon-comments", @"icon-folder-open", @"icon-code", @"icon-user"];
itemsColorList = @[@"0x3bbd79", @"0x25c2d5", @"0x3899d0", @"0xf8b327", @"0xee8c35", @"0xe7683d"];
itemsTitleList = @[@"动态", @"任务", @"讨论", @"文件", @"代码", @"成员"];
}else if ([reuseIdentifier isEqualToString:kCellIdentifier_ProjectItemsCell_Public]){
itemsNum = 4;
itemsNumInLine = 4;
itemsIconList = @[@"icon-bolt", @"icon-comments", @"icon-code", @"icon-user"];
itemsColorList = @[@"0x3bbd79", @"0x3899d0", @"0xee8c35", @"0xe7683d"];
itemsTitleList = @[@"动态", @"讨论", @"代码", @"成员"];
}
if (MIN(MIN(itemsIconList.count, itemsColorList.count), itemsTitleList.count) < itemsNum || itemsNum <= 0) {
return self;
}else{
_items = [[NSMutableArray alloc] initWithCapacity:itemsNum];
CGFloat itemWidth = kScreen_Width/itemsNumInLine;
for (int i = 0; i < itemsNum; i++) {
CGRect frame = CGRectMake(itemWidth *(i%itemsNumInLine), ProjectItemsCell_PadingHeight+ ProjectItemsCell_ItemHeight *(i/itemsNumInLine), itemWidth, ProjectItemsCell_ItemHeight);
UIButton *item = [self itemWithFrame:frame icon:itemsIconList[i] color:itemsColorList[i] title:itemsTitleList[i] index:i];
[self.contentView addSubview:item];
[_items addObject:item];
}
}
}
return self;
}
- (void)setCurProject:(Project *)curProject{
_curProject = curProject;
if (!_curProject) {
return;
}
}
+ (CGFloat)cellHeightWithObj:(id)obj{
CGFloat cellHeight = 0;
if ([obj isKindOfClass:[Project class]]) {
Project *curProject = (Project *)obj;
cellHeight = ProjectItemsCell_ItemHeight *(curProject.is_public.boolValue? 1: 2);
cellHeight += 2* ProjectItemsCell_PadingHeight;
}
return cellHeight;
}
#pragma mark ButtonItem
#define kProjectItemsCell_ItemIconTag 100
- (UIButton *)itemWithFrame:(CGRect)frame icon:(NSString *)iconStr color:(NSString *)colorStr title:(NSString *)titleStr index:(NSInteger)index{
UIButton *item = [[UIButton alloc] initWithFrame:frame];
CGFloat iconWidth = kScaleFrom_iPhone5_Desgin(46);
UIImage *itemImg = [UIImage imageWithIcon:iconStr backgroundColor:[UIColor clearColor] iconColor:[UIColor whiteColor] iconScale:1.0 andSize:CGSizeMake(iconWidth/2.8, iconWidth/2.8)];
UIImageView *itemImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, iconWidth, iconWidth)];
itemImgView.tag = kProjectItemsCell_ItemIconTag;
itemImgView.contentMode = UIViewContentModeCenter;
itemImgView.layer.masksToBounds = YES;
itemImgView.layer.cornerRadius = itemImgView.frame.size.width/2;
[itemImgView setImage:itemImg];
[itemImgView setBackgroundColor:[UIColor colorWithHexString:colorStr]];
UILabel *titleL = [[UILabel alloc] init];
titleL.textAlignment = NSTextAlignmentCenter;
titleL.font = [UIFont systemFontOfSize:13];
titleL.textColor = [UIColor colorWithHexString:@"0x222222"];
titleL.text = titleStr;
// CGFloat pading_IconToTitle = kScaleFrom_iPhone5_Desgin(10);
// CGFloat pading = (CGRectGetHeight(item.frame) - iconWidth - 15 - pading_IconToTitle)/2;
CGFloat pading = (CGRectGetHeight(item.frame) - iconWidth - 15)/3;
[item addSubview:itemImgView];
[item addSubview:titleL];
[itemImgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(item.mas_centerX);
make.top.equalTo(item.mas_top).offset(pading);
make.size.mas_equalTo(CGSizeMake(iconWidth, iconWidth));
}];
[titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.left.right.equalTo(item);
make.bottom.equalTo(item.mas_bottom).offset(-pading);
make.bottom.equalTo(item.mas_centerY).offset(iconWidth/2);
make.height.mas_equalTo(15);
}];
[item bk_addEventHandler:^(id sender) {
if (self.itemClickedBlock) {
self.itemClickedBlock(index);
}
} forControlEvents:UIControlEventTouchUpInside];
return item;
}
@end