123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- //
- // RQExerciseOptionCell.m
- // JSJP
- //
- // Created by 张嵘 on 2021/8/12.
- //
- #import "RQExerciseOptionCell.h"
- @interface RQExerciseOptionCell ()
- @property (nonatomic, readwrite, strong) RQExerciseOptionItemViewModel *viewModel;
- @property (weak, nonatomic) IBOutlet QMUIButton *optionBtn;
- @property (weak, nonatomic) IBOutlet UILabel *optionLabel;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *optionBtnWidth;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *labelHeight;
- @end
- @implementation RQExerciseOptionCell
- #pragma mark - PublicMethods
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- static NSString *ID = @"RQExerciseOptionCell";
- RQExerciseOptionCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
- if (!cell) {
- cell = [self rq_viewFromXib];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.optionBtn.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.16].CGColor;
- }
- return cell;
- }
- - (void)bindViewModel:(RQExerciseOptionItemViewModel *)viewModel {
- @weakify(self)
- _viewModel = viewModel;
- RAC(self.optionLabel, attributedText) = [[RACObserve(viewModel, optsString) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
-
- RAC(self.labelHeight, constant) = [[RACObserve(viewModel, labelHeight) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
-
- RAC(self, optionBtn) = [[[RACSignal combineLatest:@[[RACObserve(RQ_Exercise_Module, exerciseFontSize) takeUntil:self.rac_prepareForReuseSignal],[RACObserve(viewModel, btnBgColor) takeUntil:self.rac_prepareForReuseSignal]] reduce:^(NSNumber *exerciseFontSize, UIColor *btnBgColor) {
- @strongify(self)
- QMUIButton *myOptionBtn = self.optionBtn;
- [myOptionBtn setTitleNormal:viewModel.title];
- myOptionBtn.titleLabel.font = [UIFont systemFontOfSize:exerciseFontSize.integerValue];
- CGFloat btnWidth = RQ_FIT_HORIZONTAL(30.f) + (exerciseFontSize.integerValue - 17);
- self.optionBtnWidth.constant = btnWidth;
- myOptionBtn.layer.cornerRadius = btnWidth / 2.f;
- myOptionBtn.layer.masksToBounds = NO;
- myOptionBtn.layer.shadowOffset = CGSizeMake(0, 2);
- myOptionBtn.layer.shadowRadius = 6;
- myOptionBtn.layer.opacity = 1;
- myOptionBtn.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.16].CGColor;
- myOptionBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 5);
- if (RQStringIsEmpty(viewModel.title)) {
- if ([btnBgColor isEqual:RQ_MAIN_TEXT_COLOR_RED]) {
- [myOptionBtn setImage:RQImageNamed(@"ErrorOption") forState:UIControlStateNormal];
- } else if ([btnBgColor isEqual:RQ_MAIN_TEXT_COLOR_GREEN]) {
- [myOptionBtn setImage:RQImageNamed(@"CorrectOption") forState:UIControlStateNormal];
- }
- }
-
- UIImage *btnBackgroundImage = [UIImage qmui_imageWithColor:btnBgColor size:CGSizeMake(btnWidth, btnWidth) cornerRadius:btnWidth / 2.f];
- [myOptionBtn setBackgroundImage:btnBackgroundImage forState:UIControlStateNormal];
- if ([btnBgColor isEqual:RQ_MAIN_TEXT_COLOR_WHITE]) {
- [myOptionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_1 forState:UIControlStateNormal];
- } else {
- [myOptionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
- }
-
- return myOptionBtn;
- }] deliverOnMainThread] takeUntil:self.rac_prepareForReuseSignal];
- }
- #pragma mark - SystemMethods
- - (void)awakeFromNib {
- [super awakeFromNib];
-
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- }
- @end
|