123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- //
- // RQExerciseOptionCell.m
- // SDJK
- //
- // Created by 张嵘 on 2021/8/12.
- //
- #import "RQExerciseOptionCell.h"
- @interface RQExerciseOptionCell ()
- @property (nonatomic, readwrite, strong) RQExerciseOptionItemViewModel *viewModel;
- @property (weak, nonatomic) IBOutlet UIButton *optionBtn;
- @property (weak, nonatomic) IBOutlet UILabel *optionLabel;
- @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 {
- _viewModel = viewModel;
- [self.optionBtn setTitleNormal:viewModel.title];
- self.optionLabel.font = [UIFont systemFontOfSize:RQ_Exercise_Module.exerciseFontSize];
- self.optionLabel.attributedText = viewModel.optsString;
- switch (viewModel.exerciseOptionItemType) {
- case RQExerciseOptionItemType_Correct_CorrectOption: {
- [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
- if (_viewModel.exerciseType == RQExerciseType_Recitation) {
- [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
- [self.optionBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_MAIN_TEXT_COLOR_GREEN size:CGSizeMake(30, 30) cornerRadius:15] forState:UIControlStateNormal];
- } else {
- [self.optionBtn setBackgroundImage:RQImageNamed(@"CorrectOption") forState:UIControlStateNormal];
- }
- }
- break;
-
- case RQExerciseOptionItemType_Error_CorrectOption: {
- if ([viewModel.exerciseModel.answer containsString:@"-"]) {
- if ([viewModel.exerciseModel.userAnswer containsString:viewModel.optsString.string]) {
- [self.optionBtn setBackgroundImage:RQImageNamed(@"CorrectOption") forState:UIControlStateNormal];
- } else {
- [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
-
- [self.optionBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_MAIN_TEXT_COLOR_GREEN size:CGSizeMake(30, 30) cornerRadius:15] forState:UIControlStateNormal];
- }
- } else {
- [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
- [self.optionBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_MAIN_TEXT_COLOR_GREEN size:CGSizeMake(30, 30) cornerRadius:15] forState:UIControlStateNormal];
- }
- // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_GREEN;
- }
- break;
-
- case RQExerciseOptionItemType_Correct_ErrorOption: {
- [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
- [self.optionBtn setBackgroundImage:RQStringIsEmpty(viewModel.title)? RQImageNamed(@"ErrorOption") : [UIImage qmui_imageWithColor:RQ_MAIN_TEXT_COLOR_RED size:CGSizeMake(30, 30) cornerRadius:15] forState:UIControlStateNormal];
- // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_RED;
- }
- break;
-
- case RQExerciseOptionItemType_Error_ErrorOption: {
- if ([viewModel.exerciseModel.answer containsString:@"-"]) {
- if ([viewModel.exerciseModel.userAnswer containsString:viewModel.optsString.string]) {
- [self.optionBtn setBackgroundImage:RQImageNamed(@"ErrorOption") forState:UIControlStateNormal];
- } else {
- [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
- [self.optionBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_MAIN_TEXT_COLOR_RED size:CGSizeMake(30, 30) cornerRadius:15] forState:UIControlStateNormal];
- }
- } else {
- [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
- [self.optionBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_MAIN_TEXT_COLOR_RED size:CGSizeMake(30, 30) cornerRadius:15] forState:UIControlStateNormal];
- // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_RED;
- }
-
- }
- break;
-
- case RQExerciseOptionItemType_Multiple_Primary: {
- [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
- [self.optionBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_MAIN_COLOR size:CGSizeMake(30, 30) cornerRadius:15] forState:UIControlStateNormal];
- // self.optionLabel.textColor = RQ_MAIN_COLOR;
- }
- break;
-
- default: {
- [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_1 forState:UIControlStateNormal];
- [self.optionBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_MAIN_BACKGROUNDCOLOR size:CGSizeMake(30, 30) cornerRadius:15] forState:UIControlStateNormal];
- // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
-
- }
- break;
- }
- }
- #pragma mark - SystemMethods
- - (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
- }
- /// type 0对1错2默认3多选题点后后变色 . */
- //- (void)setItem:(AnswerItem *)Item {
- // _item = Item;
- // //0对1错2默认3多选题点后后变色
- // if (Item.type == 0) {
- // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
- //
- // }else if (Item.type == 1){
- // self.optionLabel.textColor = UIColor.redColor;
- //
- // }else if (Item.type == 2){//默认和多选取消选中结果后变色
- // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
- // }else if (Item.type == 3){
- // self.optionLabel.textColor = RQ_MAIN_COLOR;
- // }
- // if (Item.picname.length > 1) {
- // [self.optionBtn setBackgroundImage:RQImageNamed(Item.picname) forState:UIControlStateNormal];
- // [self.optionBtn setTitleNormal:(Item.type == 3)? Item.picname : @""];
- // } else {
- // [self.optionBtn setBackgroundImage:(Item.type == 3)? [UIImage imageWithColor:RQ_MAIN_COLOR size:CGSizeMake(30, 30)] : RQImageNamed(Item.picname) forState:UIControlStateNormal];
- // [self.optionBtn setTitleNormal:Item.picname];
- // }
- //
- // self.optionLabel.text = Item.text;
- //}
- @end
|