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
//
// GXFPopView.m
// XFFruit
//
// Created by 陈俊俊 on 15/9/11.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "GXFPopView.h"
#import "GXFPopCell.h"
#define GXFPOpView_LeftMargin 20
#define GXFPOpView_ContentHeight 230
#define GXFPOpView_TopHeight 44
@interface GXFPopView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSArray *titleArr;
@end
@implementation GXFPopView
- (instancetype)initWithFrame:(CGRect)frame withArr:(NSArray *)titleArr{
self = [super initWithFrame:frame];
if (self) {
self.titleArr = titleArr;
[self bulidLayout];
}
return self;
}
- (void)bulidLayout{
self.backgroundColor = RGBA(0, 0, 0, 0.5);
CGRect rect = CGRectMake(GXFPOpView_LeftMargin, (ScreenSize.height - GXFPOpView_ContentHeight)/2, ScreenSize.width - GXFPOpView_LeftMargin*2, GXFPOpView_ContentHeight);
if (self.titleArr.count == 4) {
rect = CGRectMake(GXFPOpView_LeftMargin, (ScreenSize.height - GXFPOpView_ContentHeight)/2, ScreenSize.width - GXFPOpView_LeftMargin*2, GXFPOpView_ContentHeight+44);
}
UIView *bgView = [[UIView alloc]initWithFrame:rect];
bgView.backgroundColor = XXFBgColor;
bgView.layer.cornerRadius = 4;
bgView.layer.masksToBounds = YES;
[self addSubview:bgView];
UILabel *titlelabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, CGRectGetWidth(bgView.frame)- 20, GXFPOpView_TopHeight-1)];
titlelabel.text = @"选择添加项目";
titlelabel.textColor = GXF_PopView_COLOR;
[bgView addSubview:titlelabel];
UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, GXFPOpView_TopHeight-1, CGRectGetWidth(bgView.frame), 1)];
lineLabel.backgroundColor = GXF_PopView_COLOR;
[bgView addSubview:lineLabel];
rect = CGRectMake(0, GXFPOpView_TopHeight, CGRectGetWidth(bgView.frame), CGRectGetHeight(bgView.frame) - GXFPOpView_TopHeight*2);
self.tableView = [[UITableView alloc]initWithFrame:rect style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[bgView addSubview:self.tableView];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, CGRectGetHeight(bgView.frame)- GXFPOpView_TopHeight, CGRectGetWidth(bgView.frame), GXFPOpView_TopHeight);
[btn setTitle:@"返回" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
[btn setTitleColor:GXF_CONTENT_COLOR forState:UIControlStateNormal];
[bgView addSubview:btn];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.titleArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"SurveyID";
GXFPopCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[GXFPopCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if (self.titleArr.count > 0) {
NSString *titleStr = self.titleArr[indexPath.row];
[cell setTitleStr:titleStr];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *str = self.titleArr[indexPath.row];
if ([self.delegate respondsToSelector:@selector(selectRowTitle:)]) {
[self.delegate selectRowTitle:str];
}
}
- (void)backClick{
if ([self.delegate respondsToSelector:@selector(clearFromSuper)]) {
[self.delegate clearFromSuper];
}
}
@end