TopSheetView.m 4.94 KB
Newer Older
陈俊俊's avatar
陈俊俊 committed
1 2 3 4 5 6 7 8 9
//
//  TopSheetView.m
//  XFFruit
//
//  Created by 陈俊俊 on 15/8/12.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "TopSheetView.h"
n22's avatar
n22 committed
10
#import "SurveyCell.h"
陈俊俊's avatar
陈俊俊 committed
11
#define LeftMargin 15
n22's avatar
n22 committed
12
#define TopMargin 20
陈俊俊's avatar
陈俊俊 committed
13
#define LeftWidth 80
n22's avatar
n22 committed
14
#define TableHeight 44
陈俊俊's avatar
陈俊俊 committed
15
#define SpaceHeight 10
n22's avatar
n22 committed
16
#define TitleSize 16
陈俊俊's avatar
陈俊俊 committed
17

n22's avatar
n22 committed
18 19 20 21 22
@interface TopSheetView ()<UITableViewDataSource,UITableViewDelegate,HPGrowingTextViewDelegate,UITextFieldDelegate>
{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
}
陈俊俊's avatar
陈俊俊 committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
@end


@implementation TopSheetView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        //界面
        [self bulidLayout];
    }
    return self;
}

#pragma mark - 布局
- (void)bulidLayout
{
n22's avatar
n22 committed
39 40
    self.backgroundColor  = XXFBgColor;
    _dataArr = [NSMutableArray array];
陈俊俊's avatar
陈俊俊 committed
41
    NSArray *arr = @[@"标题:",@"供应商:",@"联系人:",@"联系电话:",@"加工工厂:",@"备注:"];
n22's avatar
n22 committed
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
    [_dataArr addObjectsFromArray:arr];
    
    _tableView = [[UITableView alloc]initWithFrame:(CGRectMake(0, TopMargin,self.frame.size.width, self.frame.size.height - TopMargin)) style:(UITableViewStylePlain)];
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.bounces = NO;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self addSubview:_tableView];
}
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"cellID";
    SurveyCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[SurveyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (indexPath.row ==1 || indexPath.row == 4) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
陈俊俊's avatar
陈俊俊 committed
67
        }
n22's avatar
n22 committed
68
        [self createViewInCell:cell indexPath:indexPath];
陈俊俊's avatar
陈俊俊 committed
69
    }
n22's avatar
n22 committed
70 71
    [cell setTitleStr:_dataArr[indexPath.row]];
    return cell;
陈俊俊's avatar
陈俊俊 committed
72
}
n22's avatar
n22 committed
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
-  (void)createViewInCell:(SurveyCell *)cell indexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0 || indexPath.row == 2 || indexPath.row == 3) {
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-10, TableHeight)];
        textField.textAlignment = NSTextAlignmentRight;
        textField.textColor = HexColor(@"444444");
        textField.font = FontSize(15);
        textField.returnKeyType = UIReturnKeyDone;
        textField.delegate = self;
        [cell.contentView addSubview:textField];
        if (indexPath.row == 0) {
            self.titleTextFiled = textField;
            self.titleTextFiled.placeholder = @"请输入标题";
        }else if(indexPath.row == 2){
            self.peopleTextFiled = textField;
            self.peopleTextFiled.placeholder = @"请输入联系人";
        }else if(indexPath.row == 3){
            self.phoneTextFiled = textField;
            self.phoneTextFiled.placeholder = @"请输入联系人手机";
        }
        
    }else if (indexPath.row == _dataArr.count -1){
        self.remarkTextView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-10, TableHeight)];
        self.remarkTextView.contentInset = UIEdgeInsetsMake(5, 5, 5, 0);
        self.remarkTextView.minNumberOfLines = 1;
        self.remarkTextView.maxNumberOfLines = 2;
        self.remarkTextView.font = FontSize(15);
        self.remarkTextView.textAlignment = NSTextAlignmentRight;
        self.remarkTextView.delegate = self;
        self.remarkTextView.returnKeyType = UIReturnKeyDone;
        self.remarkTextView.placeholder = @"输入备注内容";
        [cell.contentView addSubview:self.remarkTextView];
    }else{
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:(CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-10, TableHeight))];
        contentLabel.textAlignment= NSTextAlignmentRight;
        contentLabel.textColor = HexColor(@"bbbbbb");
        contentLabel.font = FontSize(TitleSize);
        [cell.contentView addSubview:contentLabel];
        if (indexPath.row == 1) {
            contentLabel.text = @"选择供应商";
            self.supplierLabel = contentLabel;
            
        }else if(indexPath.row == 4){
            contentLabel.text = @"选择加工工厂";
            self.factoryLabel = contentLabel;
            
        }
    }
陈俊俊's avatar
陈俊俊 committed
120 121 122 123 124 125 126 127 128 129 130 131
}

- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView{
    [self.remarkTextView resignFirstResponder];
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.delegate hiddenKeyBoard];
    return YES;
}

@end