123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #import "PickView.h"
- @interface PickView()<UITableViewDataSource,UITableViewDelegate>
- {
- UITableView* myTableView;
-
- /**保存那些删除时间段的按钮。数目为defState.planTimes.count;
- */
- NSMutableArray* btns;
-
- /**用于动画,不过已废弃。不好看。
- */
- UIView* centerV;
-
- UIButton* btnSt,*btnEnd;
-
- }
- @end
- @implementation PickView
- -(id)initWithTitle:(NSString*)tit Models:(NSArray*)mods
- {
- self = [super initWithFrame:kFrame];
- if (self) {
- _models = mods;
- _title = tit;
-
- [self setBackgroundColor:[UIColor colorWithWhite:.01 alpha:.3]];
- UIView* aView,*line;UILabel* label; UIButton* btn;
-
- CGFloat x,y,w,h,bd;
- bd = 10;
- w = kSize.width - bd*2;
- h = 40;
- x = 0;
- y = 0;
- aView = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h*8 + 10)];
- aView.center = CGPointMake(kSize.width/2.0, kSize.height/2.0);
- [self addSubview:aView];
- [aView setBackgroundColor:[UIColor whiteColor]];
- centerV = aView;
-
- y = 0;
- label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [label setText:@"请选择时间"];
- if (tit) {
- [label setText:tit];
- }
-
- [aView addSubview:label];
- [label setTextAlignment:NSTextAlignmentCenter];
-
- y += h;
- line = [[UIView alloc] initWithFrame:CGRectMake(0, y, w, 3)];
- [line setBackgroundColor:defGreen];
- [aView addSubview:line];
-
- // x = bd;
- y += 1;
- h *= 6;
- UITableView *tv = [[UITableView alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [tv setDataSource:self];
- [tv setDelegate:self];
- [aView addSubview:tv];
- [tv setTableHeaderView:[UIView new]];
- myTableView = tv;
-
- y += h;
- h /=6.0;
- w = 200;
- x = (kSize.width - w)*.5;
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y+5, w, h)];
- [btn setTitle:@"取消" forState:UIControlStateNormal];
- [btn setBackgroundColor:defGreen];
- [btn corner:h*.5];
- [btn addTarget:self action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside];
- [aView addSubview:btn];
- }
-
- return self;
- }
- #pragma mark -
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return _models.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@""];
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@""];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- }
- [cell.textLabel setText:_models[indexPath.row]];
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- if (clkBlock) {
- NSString* str = [NSString stringWithFormat:@"%d",(int)indexPath.row];
- clkBlock(str);
- }
- [self removeFromSuperview];
- }
- -(void)completion:(MyBlockType)comp
- {
- clkBlock = comp;
- }
- -(void)show
- {
- [[UIApplication sharedApplication].keyWindow addSubview:self];
- }
- @end
|