123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //
- // SPSBHorizontalListTableView.m
- // 我的社保
- //
- // Created by jiaxian_he on 2021/5/29.
- //
- #import "SPSBHorizontalListTableView.h"
- #import "SPSBUIGeneralHeader.h"
- @interface SPSBHorizontalListTableView ()<UITableViewDelegate, UITableViewDataSource> {
- NSDictionary *_data;
- bool _isContentRightAlignment;
- bool _isLittleLayout;
- }
- @end
- @implementation SPSBHorizontalListTableView
- - (instancetype)initWithData:(nullable NSDictionary *)data isContentRightAlignment:(bool)isContentRightAlignment isLittleLayout:(bool)isLittleLayout {
- self = [super initWithFrame:CGRectZero style:UITableViewStylePlain];
- if (!self) return nil;
- _isContentRightAlignment = isContentRightAlignment;
- _isLittleLayout = isLittleLayout;
- _data = data;
- [self setupTableView];
- return self;
- }
- - (CGFloat)spsb_height {
- if (!_data || ((NSArray *)_data[@"title"]).count == 0) return 0;
- return ((NSArray *)_data[@"title"]).count * 25 + 20;
- }
- - (void)reloadData:(NSDictionary *)data {
- _data = data;
- [self reloadData];
- }
- #pragma mark - Delegate & DataSource
- static NSString * const reuseIdentifier = @"SPSBHorizontalListTableViewCell";
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- UILabel *titleLabel = [UILabel convenienceWithFont:spsb_font(_isLittleLayout ? 13 : 14) text:nil textColor:spsb_999999_color()];
- titleLabel.tag = 3000;
- [cell.contentView addSubview:titleLabel];
- [titleLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(15);
- make.centerY.equalTo(0);
- make.xContentCompressionResistance(UILayoutPriorityRequired);
- }];
-
- UILabel *contentLabel = [UILabel convenienceWithFont:spsb_font(_isLittleLayout ? 13 : 14) text:@"" textColor:_isLittleLayout ? spsb_999999_color() : spsb_666666_color() textAlignment:_isContentRightAlignment ? NSTextAlignmentRight : NSTextAlignmentLeft];
- contentLabel.tag = 3001;
- [cell.contentView addSubview:contentLabel];
- if (_isContentRightAlignment) {
- [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-15);
- make.centerY.equalTo(0);
- make.leading.greaterThanOrEqualTo(titleLabel.trailing).offset(40);
- }];
- } else {
- [contentLabel makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(titleLabel.trailing).offset(35);
- make.centerY.equalTo(0);
- make.trailing.lessThanOrEqualTo(-15);
- }];
- }
- }
- UILabel *titleLabel = [cell.contentView viewWithTag:3000];
- UILabel *contentLabel = [cell.contentView viewWithTag:3001];
- if (((NSArray *)_data[@"title"]).count > indexPath.row) {
- titleLabel.text = _data[@"title"][indexPath.row];
- contentLabel.text = _data[@"content"][indexPath.row];
-
- }
- return cell;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (!_data) return 0;
- return ((NSArray *)_data[@"title"]).count;
- }
- #pragma mark - UI
- - (void)setupTableView {
- self.scrollEnabled = false;
- self.tableHeaderView = [[UIView alloc] initWithFrame:(CGRect){0, 0, jxh_screenWidth(), 10}];
- self.tableFooterView = [[UIView alloc] initWithFrame:(CGRect){0, 0, jxh_screenWidth(), 10}];
- self.rowHeight = 25.f;
- self.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.showsHorizontalScrollIndicator = false;
- self.showsVerticalScrollIndicator = false;
- self.delegate = self;
- self.dataSource = self;
- }
- @end
|