GXFPopView.m 3.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
//
//  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
陈俊俊's avatar
陈俊俊 committed
12
#define GXFPOpView_ContentHeight 230
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#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);
34 35 36 37 38
    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];
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    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];
    
54 55
    rect = CGRectMake(0, GXFPOpView_TopHeight, CGRectGetWidth(bgView.frame), CGRectGetHeight(bgView.frame) - GXFPOpView_TopHeight*2);
    self.tableView = [[UITableView alloc]initWithFrame:rect style:UITableViewStylePlain];
56 57 58 59 60 61 62
    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];
陈俊俊's avatar
陈俊俊 committed
63
    [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
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
    [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;
}
陈俊俊's avatar
陈俊俊 committed
90 91 92 93 94 95 96 97 98 99 100
- (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];
    }
}
101 102

@end