Нет описания

FKBrandSelectView.m 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // FKBrandSelectView.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/4/28.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKBrandSelectView.h"
  9. static NSString *STANDARD_CELL_IDENTIFY = @"STANDARD_CELL_IDENTIFY";
  10. @interface FKBrandSelectView () <UITableViewDataSource, UITableViewDelegate>
  11. @property (nonatomic, strong) UIImageView *bgImgView;
  12. @property (nonatomic, strong) UITableView *tableView;
  13. @property (nonatomic, strong) UILabel *totalLabel;
  14. @property (nonatomic, strong) UIButton *totalButton;
  15. @property (nonatomic, copy) void(^aciton)(NSInteger index);
  16. @end
  17. @implementation FKBrandSelectView
  18. - (instancetype)initWithAction:(void(^)(NSInteger index))action{
  19. if (self = [super init]){
  20. self.aciton = action;
  21. }
  22. return self;
  23. }
  24. - (instancetype)initWithFrame:(CGRect)frame{
  25. if (self = [super initWithFrame:frame]) {
  26. [self addAllSubviews];
  27. }
  28. return self;
  29. }
  30. - (void)addAllSubviews{
  31. [self addSubview:self.bgImgView];
  32. [self addSubview:self.tableView];
  33. [self addSubview:self.totalLabel];
  34. [self addSubview:self.totalButton];
  35. [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.top.equalTo(self);
  37. make.centerX.equalTo(self);
  38. }];
  39. [self.totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.top.equalTo(self.bgImgView).offset(8);
  41. make.left.equalTo(self.bgImgView).offset(15);
  42. make.height.mas_equalTo(43);
  43. }];
  44. [self.totalButton mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.equalTo(self.bgImgView);
  46. make.top.equalTo(self.totalLabel);
  47. make.bottom.equalTo(self.totalLabel);
  48. make.right.equalTo(self.bgImgView);
  49. }];
  50. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.top.equalTo(self.bgImgView).offset(51);
  52. make.left.equalTo(self.bgImgView).offset(2);
  53. make.right.equalTo(self.bgImgView).offset(- 2);
  54. make.bottom.equalTo(self.bgImgView).offset(- 3);
  55. }];
  56. }
  57. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  58. return self.titleArray.count;
  59. }
  60. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  61. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:STANDARD_CELL_IDENTIFY];
  62. if (!cell){
  63. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:STANDARD_CELL_IDENTIFY];
  64. cell.textLabel.font = [UIFont systemFontOfSize:14];
  65. cell.textLabel.textColor = UIColorFromRGB(0xffffff);
  66. cell.backgroundColor = [UIColor clearColor];
  67. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  68. }
  69. cell.textLabel.text = [self titleForIndex:indexPath.row];
  70. return cell;
  71. }
  72. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  73. return 30;
  74. }
  75. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  76. [self selectAtIndex:indexPath.row];
  77. }
  78. #pragma mark - method
  79. - (NSString *)titleForIndex:(NSUInteger)index{
  80. if (index < self.titleArray.count){
  81. return self.titleArray[index];
  82. }
  83. return nil;
  84. }
  85. - (void)selectAtIndex:(NSInteger)index{
  86. if (self.aciton){
  87. self.aciton(index);
  88. }
  89. }
  90. - (void)clickTotoal{
  91. [self selectAtIndex:- 1];
  92. }
  93. #pragma mark - property
  94. - (void)setTitleArray:(NSArray *)titleArray{
  95. _titleArray = titleArray;
  96. [self.tableView reloadData];
  97. }
  98. - (UIImageView *)bgImgView{
  99. if (_bgImgView == nil) {
  100. _bgImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"book_Mask"]];
  101. }
  102. return _bgImgView;
  103. }
  104. - (UITableView *)tableView{
  105. if (_tableView == nil) {
  106. _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  107. _tableView.dataSource = self;
  108. _tableView.delegate = self;
  109. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  110. _tableView.backgroundColor = [UIColor clearColor];
  111. }
  112. return _tableView;
  113. }
  114. - (UIButton *)totalButton{
  115. if (_totalButton == nil) {
  116. _totalButton = [UIButton buttonWithType:UIButtonTypeCustom];
  117. [_totalButton addTarget:self action:@selector(clickTotoal) forControlEvents:UIControlEventTouchUpInside];
  118. }
  119. return _totalButton;
  120. }
  121. - (UILabel *)totalLabel{
  122. if (_totalLabel == nil) {
  123. _totalLabel = [[UILabel alloc]init];
  124. _totalLabel.textColor = UIColorFromRGB(0xffffff);
  125. _totalLabel.font = [UIFont systemFontOfSize:14];
  126. _totalLabel.text = @"全部";
  127. }
  128. return _totalLabel;
  129. }
  130. @end