123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- //
- // LDMiddlePlanView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/11/21.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDMiddlePlanView.h"
- #import "LDMiddlePrvilegeModel.h"
- @interface LDMiddlePlanView ()<UITableViewDelegate,UITableViewDataSource>
- {
- NSArray *_dataArr;
- }
- @property (nonatomic, strong) UITableView *tableView;
- @end
- @implementation LDMiddlePlanView
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self initUI];
- [self loadData];
- }
- return self;
- }
- - (void)initUI {
- [self addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
- }];
- }
- - (void)loadData {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/getPrivilege",BaseURL];
- [LDHttp post:url params:nil success:^(id json) {
- _dataArr = [NSArray yy_modelArrayWithClass:[LDMiddlePrvilegeModel class] json:json[@"data"][@"speed"]];
- [self.tableView reloadData];
- [self mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(40+_dataArr.count*40);
- }];
- [self layoutIfNeeded];
- if (self.layoutComplete) {
- self.layoutComplete();
- }
-
- } failure:^(NSError *error) {
-
- }];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return _dataArr.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 40;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 40;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- middleCell *cell = [middleCell cellWithTableView:tableView];
- LDMiddlePrvilegeModel *model = _dataArr[indexPath.row];
- cell.model = model;
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- LDMiddlePrvilegeModel *model = _dataArr[indexPath.row];
- if (self.selectedBlock) {
- self.selectedBlock(model);
- }
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 40)];
- UILabel *title = [[UILabel alloc] init];
- title.font = [UIFont systemFontOfSize:15];
- title.textColor = [UIColor YHColorWithHex:0x333333];
- title.textAlignment = NSTextAlignmentCenter;
- title.text = @"当前进度";
- [header addSubview:title];
- [title mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(header.mas_centerX);
- make.centerY.mas_equalTo(header.mas_centerY);
- }];
-
- UIView *left = [[UIView alloc] init];
- left.backgroundColor = [UIColor YHColorWithHex:0x333333];
- [header addSubview:left];
- [left mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(title.mas_left).mas_offset(-10);
- make.centerY.mas_equalTo(title.mas_centerY);
- make.height.mas_equalTo(2);
- make.width.mas_equalTo(40);
- }];
-
- UIView *right = [[UIView alloc] init];
- right.backgroundColor = [UIColor YHColorWithHex:0x333333];
- [header addSubview:right];
- [right mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(title.mas_right).mas_offset(10);
- make.centerY.mas_equalTo(title.mas_centerY);
- make.height.mas_equalTo(2);
- make.width.mas_equalTo(40);
- }];
- return header;
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.sectionFooterHeight = 0;
- _tableView.sectionHeaderHeight = 0;
- _tableView.estimatedRowHeight = 0;
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- _tableView.bounces = NO;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
-
-
- }
- return _tableView;
- }
- @end
- #pragma mark ----------------
- @interface middleCell ()
- @property (nonatomic, strong) UIImageView *imgView;
- @property (nonatomic, strong) UILabel *titleLb;
- @property (nonatomic, strong) UILabel *detailLb;
- @property (nonatomic, strong) UIImageView *rightIcon;
- @end
- @implementation middleCell : UITableViewCell
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- static NSString *cellID = nil;
- cellID = NSStringFromClass([self class]);
- middleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (!cell) {
- cell = [[middleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return cell;
-
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self initUI];
- }
- return self;
- }
- - (void)initUI {
- [self.contentView addSubview:self.imgView];
- [self.contentView addSubview:self.titleLb];
- [self.contentView addSubview:self.detailLb];
- [self.contentView addSubview:self.rightIcon];
-
- [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(17);
- make.centerY.mas_equalTo(self.mas_centerY);
- make.width.height.mas_equalTo(22);
- }];
-
- [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.imgView.mas_right).mas_offset(25);
- make.centerY.mas_equalTo(self.mas_centerY);
- }];
-
- [self.rightIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(-10);
- make.centerY.mas_equalTo(self.mas_centerY);
- make.width.height.mas_equalTo(20);
- }];
-
- [self.detailLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(self.rightIcon.mas_left).mas_offset(-5);
- make.centerY.mas_equalTo(self.mas_centerY);
- }];
- }
- - (void)setModel:(LDMiddlePrvilegeModel *)model {
- _model = model;
- [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.img]];
- self.titleLb.text = model.title;
- self.detailLb.text = model.content;
-
- }
- - (UIImageView *)imgView {
- if (!_imgView) {
- _imgView = [[UIImageView alloc] init];
- }
- return _imgView;
- }
- - (UILabel *)titleLb {
- if (!_titleLb) {
- _titleLb = [[UILabel alloc] init];
- _titleLb.textColor = [UIColor YHColorWithHex:0x333333];
- _titleLb.font = [UIFont systemFontOfSize:13];
- }
- return _titleLb;
- }
- - (UILabel *)detailLb {
- if (!_detailLb) {
- _detailLb = [[UILabel alloc] init];
- _detailLb.textColor = [UIColor YHColorWithHex:0x333333];
- _detailLb.font = [UIFont systemFontOfSize:13];
- _detailLb.textAlignment = NSTextAlignmentRight;
- }
- return _detailLb;
- }
- - (UIImageView *)rightIcon {
- if (!_rightIcon) {
- _rightIcon = [[UIImageView alloc] init];
- _rightIcon.image = [UIImage imageNamed:@"more_acc"];
- }
- return _rightIcon;
- }
- @end
|