123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- //
- // FKBrandSelectView.m
- // FirstLink
- //
- // Created by jack on 16/4/28.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKBrandSelectView.h"
- static NSString *STANDARD_CELL_IDENTIFY = @"STANDARD_CELL_IDENTIFY";
- @interface FKBrandSelectView () <UITableViewDataSource, UITableViewDelegate>
- @property (nonatomic, strong) UIImageView *bgImgView;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) UILabel *totalLabel;
- @property (nonatomic, strong) UIButton *totalButton;
-
- @property (nonatomic, copy) void(^aciton)(NSInteger index);
- @end
- @implementation FKBrandSelectView
- - (instancetype)initWithAction:(void(^)(NSInteger index))action{
- if (self = [super init]){
- self.aciton = action;
- }
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- [self addAllSubviews];
- }
- return self;
- }
- - (void)addAllSubviews{
-
- [self addSubview:self.bgImgView];
- [self addSubview:self.tableView];
- [self addSubview:self.totalLabel];
- [self addSubview:self.totalButton];
-
- [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self);
- make.centerX.equalTo(self);
- }];
-
- [self.totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgImgView).offset(8);
- make.left.equalTo(self.bgImgView).offset(15);
- make.height.mas_equalTo(43);
- }];
-
- [self.totalButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bgImgView);
- make.top.equalTo(self.totalLabel);
- make.bottom.equalTo(self.totalLabel);
- make.right.equalTo(self.bgImgView);
- }];
-
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgImgView).offset(51);
- make.left.equalTo(self.bgImgView).offset(2);
- make.right.equalTo(self.bgImgView).offset(- 2);
- make.bottom.equalTo(self.bgImgView).offset(- 3);
- }];
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.titleArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:STANDARD_CELL_IDENTIFY];
- if (!cell){
- cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:STANDARD_CELL_IDENTIFY];
- cell.textLabel.font = [UIFont systemFontOfSize:14];
- cell.textLabel.textColor = UIColorFromRGB(0xffffff);
- cell.backgroundColor = [UIColor clearColor];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- cell.textLabel.text = [self titleForIndex:indexPath.row];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 30;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [self selectAtIndex:indexPath.row];
- }
- #pragma mark - method
- - (NSString *)titleForIndex:(NSUInteger)index{
- if (index < self.titleArray.count){
- return self.titleArray[index];
- }
- return nil;
- }
- - (void)selectAtIndex:(NSInteger)index{
- if (self.aciton){
- self.aciton(index);
- }
- }
- - (void)clickTotoal{
- [self selectAtIndex:- 1];
- }
- #pragma mark - property
- - (void)setTitleArray:(NSArray *)titleArray{
- _titleArray = titleArray;
- [self.tableView reloadData];
- }
- - (UIImageView *)bgImgView{
- if (_bgImgView == nil) {
- _bgImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"book_Mask"]];
- }
- return _bgImgView;
- }
- - (UITableView *)tableView{
-
- if (_tableView == nil) {
- _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = [UIColor clearColor];
- }
- return _tableView;
- }
- - (UIButton *)totalButton{
- if (_totalButton == nil) {
- _totalButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_totalButton addTarget:self action:@selector(clickTotoal) forControlEvents:UIControlEventTouchUpInside];
- }
- return _totalButton;
- }
- - (UILabel *)totalLabel{
- if (_totalLabel == nil) {
- _totalLabel = [[UILabel alloc]init];
- _totalLabel.textColor = UIColorFromRGB(0xffffff);
- _totalLabel.font = [UIFont systemFontOfSize:14];
- _totalLabel.text = @"全部";
- }
- return _totalLabel;
- }
- @end
|