ScreenView.m 9.75 KB
Newer Older
1 2 3 4 5 6 7 8 9
//
//  ScreenView.m
//  redstar
//
//  Created by admin on 15/11/11.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "ScreenView.h"
10 11 12 13 14 15 16 17 18 19 20 21
#import "GroupItems.h"

#define SELECTED_VIEW_CONTROLLER_TAG 98456345
#define kScreenTabelViewCell @"screenTableViewCell"

@interface ScreenView () <GroupTabBarDelegate, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate>
@property (nonatomic, strong) UILabel *placeholderLabel1;

@property (nonatomic, strong) NSArray *testArray;

@property (nonatomic, strong) UIView *backView;
@end
22 23 24

@implementation ScreenView

25
- (instancetype)initWithTitleArray:(NSArray *)titleArray
26 27 28
{
    self = [super init];
    if (self) {
29
        [self setupWithTitleArray:titleArray];
30 31 32 33
    }
    return self;
}

34
- (instancetype)initWithFrame:(CGRect)frame titleArray:(NSArray *)titleArray
35 36 37
{
    self = [super initWithFrame:frame];
    if (self) {
38
        [self setupWithTitleArray:titleArray];
39 40 41 42
    }
    return self;
}

43
- (void)setupWithTitleArray:(NSArray *)titleArray;
44
{
admin's avatar
admin committed
45 46 47
    self.testArray = [NSArray arrayWithObjects:@"一周", @"一个月",@"三个月",@"一年",@"历史更多",nil];

    
48 49 50 51
    self.groupTabBar = [[GroupTabBar alloc] initWithFrame:CGRectMake(0, 0, 100, 180)];
    _groupTabBar.delegate = self;
    [self addSubview:_groupTabBar];
    
52
    self.inspectTableView = [[InspectTableView alloc] initWithTitleArray:titleArray];
admin's avatar
admin committed
53 54 55 56
    NSInteger inspectIndex = 0;
    NSIndexPath *inspectIndexPath = [NSIndexPath indexPathForRow:inspectIndex inSection:0];
    [_inspectTableView selectRowAtIndexPath:inspectIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    GroupItems *cyanItem = [[GroupItems alloc] initWithTitle:@"状态等于" view:_inspectTableView];
57 58 59 60 61 62 63 64 65 66 67 68
    
    self.textView = [[UITextView alloc] init];
    _textView.delegate = self;
    self.placeholderLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 100, 30)];
    self.placeholderLabel1.text = @"请输入标题...";
    self.placeholderLabel1.font = [UIFont systemFontOfSize:15.0];
    self.placeholderLabel1.textColor = kOnLineCellDetailColor;
    [self.textView addSubview:self.placeholderLabel1];
    
    GroupItems *textItem = [[GroupItems alloc] initWithTitle:@"标题类似于" view:_textView];
    
    
admin's avatar
admin committed
69 70 71 72 73 74 75 76 77 78

    self.tableView = [[UITableView alloc] init];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    NSInteger selectedIndex = 0;
    NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
    [_tableView selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    GroupItems *tableItem = [[GroupItems alloc] initWithTitle:@"时间范围" view:_tableView];

    [self insertSubview:_inspectTableView belowSubview:_groupTabBar];
79
    [self insertSubview:_textView belowSubview:_groupTabBar];
admin's avatar
admin committed
80
    [self insertSubview:_tableView belowSubview:_groupTabBar];
81
    
admin's avatar
admin committed
82
    _groupTabBar.items = @[cyanItem, textItem, tableItem];
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    [_groupTabBar showIndex:0];
    
    self.backView.backgroundColor = [UIColor whiteColor];
    [self.resetBtn setTitle:@"重置" forState:UIControlStateNormal];
    [self.submitBtn setTitle:@"提交" forState:UIControlStateNormal];

}

#pragma mark - UITabelViewDelgate / DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _testArray.count;
}

// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kScreenTabelViewCell];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kScreenTabelViewCell];
    }
104
    
105 106
    cell.textLabel.text = _testArray[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:14.0];
107 108
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-duigou2"]];
admin's avatar
admin committed
109
    imageView.frame = CGRectMake(kScreenWidth - self.groupTabBar.frame.size.width-30 , 15, 19, 14);
110 111
    [cell.contentView addSubview:imageView];
    
112 113 114 115 116 117
    return cell;
}

// cell的点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
118
    
119
    if (_delegate) {
admin's avatar
admin committed
120
        [_delegate tableViewDidSelectRow:indexPath.row];
121 122 123
    }
}

admin's avatar
admin committed
124 125 126 127 128 129 130 131 132 133 134 135
#pragma mark - UITextView Delegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    if (![text isEqualToString:@""]) {
        _placeholderLabel1.hidden = YES;
        
    }
    
    if ([text isEqualToString:@""] && range.location == 0 && range.length == 1) {
        _placeholderLabel1.hidden = NO;
        
    }
    
admin's avatar
admin committed
136 137 138 139 140 141
    if ([text isEqualToString:@"\n"]) {
        [self.textView resignFirstResponder];
        return NO;
    }

    
admin's avatar
admin committed
142 143 144 145
    return YES;
}


146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188

- (void)switchView:(UIView *)view
{
    UIView *currentView = [self viewWithTag:SELECTED_VIEW_CONTROLLER_TAG];
    [currentView removeFromSuperview];
    currentView = nil;
    
    view.frame = CGRectMake(self.groupTabBar.frame.size.width,0,kScreenWidth - self.groupTabBar.frame.size.width, self.groupTabBar.size.height);
    
    view.tag = SELECTED_VIEW_CONTROLLER_TAG;
    
    [self insertSubview:view belowSubview:_groupTabBar];
    
}

- (UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc] init];
        _backView.translatesAutoresizingMaskIntoConstraints = NO;
        [self addSubview:_backView];
        
        NSLayoutConstraint *lineViewTop = [NSLayoutConstraint constraintWithItem:_backView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.groupTabBar attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self addConstraint:lineViewTop];
        
        NSLayoutConstraint *lineViewRight = [NSLayoutConstraint constraintWithItem:_backView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
        [self addConstraint:lineViewRight];
        
        NSLayoutConstraint *lineViewBottom = [NSLayoutConstraint constraintWithItem:_backView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self addConstraint:lineViewBottom];
        
        NSLayoutConstraint *lineViewLeft = [NSLayoutConstraint constraintWithItem:_backView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self addConstraint:lineViewLeft];
    }
    return _backView;
}

- (UIButton *)resetBtn
{
    if (!_resetBtn) {
        _resetBtn = [[UIButton alloc] init];
        _resetBtn.backgroundColor = [UIColor grayColor];
        _resetBtn.translatesAutoresizingMaskIntoConstraints = NO;
admin's avatar
admin committed
189
        _resetBtn.layer.cornerRadius = 4.0;
190 191
        [self.backView addSubview:_resetBtn];
        
admin's avatar
admin committed
192
        NSLayoutConstraint *lineViewTop = [NSLayoutConstraint constraintWithItem:_resetBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.backView attribute:NSLayoutAttributeTop multiplier:1.0 constant:7.5];
193 194 195 196 197
        [self.backView addConstraint:lineViewTop];
        
        NSLayoutConstraint *lineViewRight = [NSLayoutConstraint constraintWithItem:_resetBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.backView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:-20];
        [self.backView addConstraint:lineViewRight];
        
admin's avatar
admin committed
198
        NSLayoutConstraint *lineViewBottom = [NSLayoutConstraint constraintWithItem:_resetBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.backView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-7.5];
199 200 201 202 203 204 205 206 207 208 209 210 211 212
        [self.backView addConstraint:lineViewBottom];
        
        NSLayoutConstraint *lineViewLeft = [NSLayoutConstraint constraintWithItem:_resetBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.backView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
        [self.backView addConstraint:lineViewLeft];
    }
    return _resetBtn;
}

- (UIButton *)submitBtn
{
    if (!_submitBtn) {
        _submitBtn = [[UIButton alloc] init];
        _submitBtn.backgroundColor = kNavigationBarColor;
        _submitBtn.translatesAutoresizingMaskIntoConstraints = NO;
admin's avatar
admin committed
213
        _submitBtn.layer.cornerRadius = 4.0;
214 215
        [self.backView addSubview:_submitBtn];
        
admin's avatar
admin committed
216
        NSLayoutConstraint *lineViewTop = [NSLayoutConstraint constraintWithItem:_submitBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.backView attribute:NSLayoutAttributeTop multiplier:1.0 constant:7.5];
217 218 219 220 221
        [self.backView addConstraint:lineViewTop];
        
        NSLayoutConstraint *lineViewRight = [NSLayoutConstraint constraintWithItem:_submitBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.backView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [self.backView addConstraint:lineViewRight];
        
admin's avatar
admin committed
222
        NSLayoutConstraint *lineViewBottom = [NSLayoutConstraint constraintWithItem:_submitBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.backView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-7.5];
223 224 225 226 227 228
        [self.backView addConstraint:lineViewBottom];
        
        NSLayoutConstraint *lineViewLeft = [NSLayoutConstraint constraintWithItem:_submitBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.backView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:20];
        [self.backView addConstraint:lineViewLeft];
    }
    return _submitBtn;
229 230
}

admin's avatar
admin committed
231 232


233 234 235 236 237 238 239 240 241
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end