猎豆优选

LDMiddlePlanView.m 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. //
  2. // LDMiddlePlanView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/11/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDMiddlePlanView.h"
  9. #import "LDMiddlePrvilegeModel.h"
  10. @interface LDMiddlePlanView ()<UITableViewDelegate,UITableViewDataSource>
  11. {
  12. NSArray *_dataArr;
  13. }
  14. @property (nonatomic, strong) UITableView *tableView;
  15. @end
  16. @implementation LDMiddlePlanView
  17. - (instancetype)initWithFrame:(CGRect)frame
  18. {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self initUI];
  22. [self loadData];
  23. }
  24. return self;
  25. }
  26. - (void)initUI {
  27. [self addSubview:self.tableView];
  28. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
  30. }];
  31. }
  32. - (void)loadData {
  33. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/getPrivilege",BaseURL];
  34. [LDHttp post:url params:nil success:^(id json) {
  35. _dataArr = [NSArray yy_modelArrayWithClass:[LDMiddlePrvilegeModel class] json:json[@"data"][@"speed"]];
  36. [self.tableView reloadData];
  37. [self mas_updateConstraints:^(MASConstraintMaker *make) {
  38. make.height.mas_equalTo(40+_dataArr.count*40);
  39. }];
  40. [self layoutIfNeeded];
  41. if (self.layoutComplete) {
  42. self.layoutComplete();
  43. }
  44. } failure:^(NSError *error) {
  45. }];
  46. }
  47. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  48. return _dataArr.count;
  49. }
  50. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  51. return 40;
  52. }
  53. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  54. return 40;
  55. }
  56. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  57. return 0;
  58. }
  59. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  60. middleCell *cell = [middleCell cellWithTableView:tableView];
  61. LDMiddlePrvilegeModel *model = _dataArr[indexPath.row];
  62. cell.model = model;
  63. return cell;
  64. }
  65. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  66. LDMiddlePrvilegeModel *model = _dataArr[indexPath.row];
  67. if (self.selectedBlock) {
  68. self.selectedBlock(model);
  69. }
  70. }
  71. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  72. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 40)];
  73. UILabel *title = [[UILabel alloc] init];
  74. title.font = [UIFont systemFontOfSize:15];
  75. title.textColor = [UIColor YHColorWithHex:0x333333];
  76. title.textAlignment = NSTextAlignmentCenter;
  77. title.text = @"当前进度";
  78. [header addSubview:title];
  79. [title mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.centerX.mas_equalTo(header.mas_centerX);
  81. make.centerY.mas_equalTo(header.mas_centerY);
  82. }];
  83. UIView *left = [[UIView alloc] init];
  84. left.backgroundColor = [UIColor YHColorWithHex:0x333333];
  85. [header addSubview:left];
  86. [left mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.right.mas_equalTo(title.mas_left).mas_offset(-10);
  88. make.centerY.mas_equalTo(title.mas_centerY);
  89. make.height.mas_equalTo(2);
  90. make.width.mas_equalTo(40);
  91. }];
  92. UIView *right = [[UIView alloc] init];
  93. right.backgroundColor = [UIColor YHColorWithHex:0x333333];
  94. [header addSubview:right];
  95. [right mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.mas_equalTo(title.mas_right).mas_offset(10);
  97. make.centerY.mas_equalTo(title.mas_centerY);
  98. make.height.mas_equalTo(2);
  99. make.width.mas_equalTo(40);
  100. }];
  101. return header;
  102. }
  103. - (UITableView *)tableView {
  104. if (!_tableView) {
  105. _tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
  106. _tableView.estimatedSectionHeaderHeight = 0;
  107. _tableView.estimatedSectionFooterHeight = 0;
  108. _tableView.sectionFooterHeight = 0;
  109. _tableView.sectionHeaderHeight = 0;
  110. _tableView.estimatedRowHeight = 0;
  111. _tableView.delegate = self;
  112. _tableView.dataSource = self;
  113. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  114. _tableView.bounces = NO;
  115. _tableView.showsVerticalScrollIndicator = NO;
  116. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  117. }
  118. return _tableView;
  119. }
  120. @end
  121. #pragma mark ----------------
  122. @interface middleCell ()
  123. @property (nonatomic, strong) UIImageView *imgView;
  124. @property (nonatomic, strong) UILabel *titleLb;
  125. @property (nonatomic, strong) UILabel *detailLb;
  126. @property (nonatomic, strong) UIImageView *rightIcon;
  127. @end
  128. @implementation middleCell : UITableViewCell
  129. + (instancetype)cellWithTableView:(UITableView *)tableView {
  130. static NSString *cellID = nil;
  131. cellID = NSStringFromClass([self class]);
  132. middleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  133. if (!cell) {
  134. cell = [[middleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  135. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  136. }
  137. return cell;
  138. }
  139. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  140. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  141. if (self) {
  142. [self initUI];
  143. }
  144. return self;
  145. }
  146. - (void)initUI {
  147. [self.contentView addSubview:self.imgView];
  148. [self.contentView addSubview:self.titleLb];
  149. [self.contentView addSubview:self.detailLb];
  150. [self.contentView addSubview:self.rightIcon];
  151. [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  152. make.left.mas_equalTo(17);
  153. make.centerY.mas_equalTo(self.mas_centerY);
  154. make.width.height.mas_equalTo(22);
  155. }];
  156. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  157. make.left.mas_equalTo(self.imgView.mas_right).mas_offset(25);
  158. make.centerY.mas_equalTo(self.mas_centerY);
  159. }];
  160. [self.rightIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  161. make.right.mas_equalTo(-10);
  162. make.centerY.mas_equalTo(self.mas_centerY);
  163. make.width.height.mas_equalTo(20);
  164. }];
  165. [self.detailLb mas_makeConstraints:^(MASConstraintMaker *make) {
  166. make.right.mas_equalTo(self.rightIcon.mas_left).mas_offset(-5);
  167. make.centerY.mas_equalTo(self.mas_centerY);
  168. }];
  169. }
  170. - (void)setModel:(LDMiddlePrvilegeModel *)model {
  171. _model = model;
  172. [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.img]];
  173. self.titleLb.text = model.title;
  174. self.detailLb.text = model.content;
  175. }
  176. - (UIImageView *)imgView {
  177. if (!_imgView) {
  178. _imgView = [[UIImageView alloc] init];
  179. }
  180. return _imgView;
  181. }
  182. - (UILabel *)titleLb {
  183. if (!_titleLb) {
  184. _titleLb = [[UILabel alloc] init];
  185. _titleLb.textColor = [UIColor YHColorWithHex:0x333333];
  186. _titleLb.font = [UIFont systemFontOfSize:13];
  187. }
  188. return _titleLb;
  189. }
  190. - (UILabel *)detailLb {
  191. if (!_detailLb) {
  192. _detailLb = [[UILabel alloc] init];
  193. _detailLb.textColor = [UIColor YHColorWithHex:0x333333];
  194. _detailLb.font = [UIFont systemFontOfSize:13];
  195. _detailLb.textAlignment = NSTextAlignmentRight;
  196. }
  197. return _detailLb;
  198. }
  199. - (UIImageView *)rightIcon {
  200. if (!_rightIcon) {
  201. _rightIcon = [[UIImageView alloc] init];
  202. _rightIcon.image = [UIImage imageNamed:@"more_acc"];
  203. }
  204. return _rightIcon;
  205. }
  206. @end