123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- //
- // XYMedalListTableViewCell.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/1/13.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYMedalListTableViewCell.h"
- #import "XYMedalListCellModel.h"
- #import "CustomSwitch.h"
- @interface XYMedalListTableViewCell ()
- @property (nonatomic, strong) UIView *medalBgView;
- @property (nonatomic, strong) UIImageView *medalImageView;
- @property (nonatomic, readwrite, strong) UILabel *medalNameLabel;
- @property (nonatomic, readwrite, strong) UILabel *timeLabel;
- @property (nonatomic, readwrite, strong) UIButton *useButton;
- @property (nonatomic, readwrite, strong) UIView *line;
- @property (nonatomic, readwrite, strong) NSIndexPath *indexPath;
- @end
- @implementation XYMedalListTableViewCell
- #pragma mark - Public Method
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- static NSString *cellId = @"XYMedalListTableViewCell";
- XYMedalListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
- if (!cell) {
- cell = [[XYMedalListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return cell;
- }
- - (void)configureModel:(XYMedalListCellModel *)model {
-
- [self.medalImageView sd_setImageWithURL:UrlForString(model.item.medalIcon) placeholderImage:placeholderImage()];
- self.medalNameLabel.text = model.item.medalName;
- if ([model.expireTime isEqualToString:@"-1"]) {
- self.timeLabel.text = @"";
- }else {
- self.timeLabel.text = [NSString stringWithFormat:@"%@", [SystemTimeObject dayHourMinuteDifferentTimeAnotherTime:model.expireTime]];
- }
- if (model.useStatus) {
- // 已经使用
- [self.useButton setTitle:kLocalizedString(@"启用中") forState:UIControlStateNormal];
- [self.useButton setTitleColor:Color_TextRed forState:UIControlStateNormal];
- [self.useButton setBackgroundImage:nil forState:UIControlStateNormal];
- }else {
- // 没有使用
- [self.useButton setTitle:kLocalizedString(@"启用") forState:UIControlStateNormal];
- [self.useButton setTitleColor:Color_White forState:UIControlStateNormal];
- [self.useButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[ColorFromHexString(@"#5D26FF"), ColorFromHexString(@"#9059FF")] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(54, 26)] forState:UIControlStateNormal];
- }
- }
- - (void)setIndexPath:(NSIndexPath *)indexPath rowsInSection:(NSInteger)rows {
- self.indexPath = indexPath;
- }
- #pragma mark — Action
- - (void)useButtonAction:(id)sender {
- if (self.delegate && [self.delegate respondsToSelector:@selector(swichViewDidDelayChange:atIndexPath:)]) {
- [self.delegate swichViewDidDelayChange:self.useButton.selected atIndexPath:self.indexPath];
- }
- }
- #pragma mark - 初始化
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
-
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
- // 初始化
- [self _setup];
-
- // 创建自控制器
- [self _setupSubViews];
-
- // 布局子控件
- [self _makeSubViewsConstraints];
- }
- return self;
- }
- #pragma mark - 事件处理Or辅助方法
- - (void)switchOnValueChange:(id)sender {
- //NSLog(@"switch:on:%ld", self.switchView.on);
- }
- #pragma mark - Private Method
- - (void)_setup{
- self.backgroundColor = UIColor.whiteColor;
- }
- #pragma mark - 创建子控件
- - (void)_setupSubViews{
- [self.contentView addSubview:self.medalBgView];
- [self.medalBgView addSubview:self.medalImageView];
- [self.contentView addSubview:self.medalNameLabel];
- [self.contentView addSubview:self.timeLabel];
- [self.contentView addSubview:self.useButton];
- [self.contentView addSubview:self.line];
-
- [self.useButton addTarget:self action:@selector(useButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
- [self.medalBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15.0f);
- make.centerY.equalTo(self.contentView);
- make.width.height.equalTo(@90.0f);
- }];
- [self.medalImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self.medalBgView);
- make.width.height.equalTo(@66.0f);
- }];
- [self.medalNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.medalBgView.mas_right).offset(12.0f);
- make.top.equalTo(self.medalBgView).offset(24.0f);
- make.height.equalTo(@22.0f);
- make.right.equalTo(self.useButton.mas_left).offset(-10.0f);
- }];
- [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.medalBgView.mas_right).offset(12.0f);
- make.top.equalTo(self.medalNameLabel.mas_bottom).offset(1.0f);
- make.height.equalTo(@17.0f);
- make.right.equalTo(self.useButton.mas_left).offset(-10.0f);
- }];
- [self.useButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(-SPACING_EDGE);
- make.centerY.equalTo(self.contentView);
- make.width.equalTo(@54.0f);
- make.height.equalTo(@26.0f);
- }];
- [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.medalNameLabel);
- make.bottom.right.equalTo(self.contentView);
- make.height.equalTo(@0.3f);
- }];
-
- [self.useButton addViewBorder:Color_TextRed redian:13];
- [self.medalBgView addViewBorder:Color_Clear redian:4];
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (UIView *)medalBgView {
- if (!_medalBgView) {
- _medalBgView = [UIView new];
- _medalBgView.backgroundColor = ColorFromHexString(@"#F3F3F3");
- }
- return _medalBgView;
- }
- - (UIImageView *)medalImageView {
- if (!_medalImageView) {
- _medalImageView = [UIImageView new];
- _medalImageView.contentMode = UIViewContentModeScaleAspectFit;
- _medalImageView.clipsToBounds = YES;
- }
- return _medalImageView;
- }
- - (UILabel *)medalNameLabel {
- if (!_medalNameLabel) {
- _medalNameLabel = [UILabel createLabelTextColor:Color_Nakaguro fount:Font_B(16)];
- }
- return _medalNameLabel;
- }
- - (UILabel *)timeLabel {
- if (!_timeLabel) {
- _timeLabel = [UILabel createLabelTextColor:Color_TextRed fount:Font(12)];
- }
- return _timeLabel;
- }
- - (UIButton *)useButton {
- if (!_useButton) {
- _useButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _useButton.titleLabel.font = Font(12);
- }
- return _useButton;
- }
- - (UIView *)line {
- if (!_line) {
- _line = [UIView new];
- _line.backgroundColor = Color_line;
- }
- return _line;
- }
- @end
|