RQExerciseOptionCell.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // RQExerciseOptionCell.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/8/12.
  6. //
  7. #import "RQExerciseOptionCell.h"
  8. @interface RQExerciseOptionCell ()
  9. @property (nonatomic, readwrite, strong) RQExerciseOptionItemViewModel *viewModel;
  10. @property (weak, nonatomic) IBOutlet UIButton *optionBtn;
  11. @property (weak, nonatomic) IBOutlet UILabel *optionLabel;
  12. @end
  13. @implementation RQExerciseOptionCell
  14. #pragma mark - PublicMethods
  15. + (instancetype)cellWithTableView:(UITableView *)tableView {
  16. static NSString *ID = @"RQExerciseOptionCell";
  17. RQExerciseOptionCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  18. if (!cell) {
  19. cell = [self rq_viewFromXib];
  20. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  21. cell.optionBtn.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.16].CGColor;
  22. }
  23. return cell;
  24. }
  25. - (void)bindViewModel:(RQExerciseOptionItemViewModel *)viewModel {
  26. _viewModel = viewModel;
  27. [self.optionBtn setTitleNormal:viewModel.title];
  28. self.optionLabel.attributedText = viewModel.optsString;
  29. switch (viewModel.exerciseOptionItemType) {
  30. case RQExerciseOptionItemType_Correct_CorrectOption: {
  31. [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
  32. if (_viewModel.exerciseType == RQExerciseType_Recitation) {
  33. [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
  34. [self.optionBtn setBackgroundImage:[UIImage jm_imageWithRoundedCornersAndSize:CGSizeMake(30, 30) andCornerRadius:15 andColor:RQ_MAIN_TEXT_COLOR_GREEN] forState:UIControlStateNormal];
  35. } else {
  36. [self.optionBtn setBackgroundImage:RQImageNamed(@"CorrectOption") forState:UIControlStateNormal];
  37. }
  38. }
  39. break;
  40. case RQExerciseOptionItemType_Error_CorrectOption: {
  41. if ([viewModel.exerciseModel.answer containsString:@"-"]) {
  42. if ([viewModel.exerciseModel.userAnswer containsString:viewModel.optsString.string]) {
  43. [self.optionBtn setBackgroundImage:RQImageNamed(@"CorrectOption") forState:UIControlStateNormal];
  44. } else {
  45. [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
  46. [self.optionBtn setBackgroundImage:[UIImage jm_imageWithRoundedCornersAndSize:CGSizeMake(30, 30) andCornerRadius:15 andColor:RQ_MAIN_TEXT_COLOR_GREEN] forState:UIControlStateNormal];
  47. }
  48. } else {
  49. [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
  50. [self.optionBtn setBackgroundImage:[UIImage jm_imageWithRoundedCornersAndSize:CGSizeMake(30, 30) andCornerRadius:15 andColor:RQ_MAIN_TEXT_COLOR_GREEN] forState:UIControlStateNormal];
  51. }
  52. // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_GREEN;
  53. }
  54. break;
  55. case RQExerciseOptionItemType_Correct_ErrorOption: {
  56. [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
  57. [self.optionBtn setBackgroundImage:RQStringIsEmpty(viewModel.title)? RQImageNamed(@"ErrorOption") : [UIImage jm_imageWithRoundedCornersAndSize:CGSizeMake(30, 30) andCornerRadius:15 andColor:RQ_MAIN_TEXT_COLOR_RED] forState:UIControlStateNormal];
  58. // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_RED;
  59. }
  60. break;
  61. case RQExerciseOptionItemType_Error_ErrorOption: {
  62. if ([viewModel.exerciseModel.answer containsString:@"-"]) {
  63. if ([viewModel.exerciseModel.userAnswer containsString:viewModel.optsString.string]) {
  64. [self.optionBtn setBackgroundImage:RQImageNamed(@"ErrorOption") forState:UIControlStateNormal];
  65. } else {
  66. [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
  67. [self.optionBtn setBackgroundImage:[UIImage jm_imageWithRoundedCornersAndSize:CGSizeMake(30, 30) andCornerRadius:15 andColor:RQ_MAIN_TEXT_COLOR_RED] forState:UIControlStateNormal];
  68. }
  69. } else {
  70. [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
  71. [self.optionBtn setBackgroundImage:[UIImage jm_imageWithRoundedCornersAndSize:CGSizeMake(30, 30) andCornerRadius:15 andColor:RQ_MAIN_TEXT_COLOR_RED] forState:UIControlStateNormal];
  72. // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_RED;
  73. }
  74. }
  75. break;
  76. case RQExerciseOptionItemType_Multiple_Primary: {
  77. [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_WHITE forState:UIControlStateNormal];
  78. [self.optionBtn setBackgroundImage:[UIImage jm_imageWithRoundedCornersAndSize:CGSizeMake(30, 30) andCornerRadius:15 andColor:RQ_MAIN_COLOR] forState:UIControlStateNormal];
  79. // self.optionLabel.textColor = RQ_MAIN_COLOR;
  80. }
  81. break;
  82. default: {
  83. [self.optionBtn setTitleColor:RQ_MAIN_TEXT_COLOR_1 forState:UIControlStateNormal];
  84. [self.optionBtn setBackgroundImage:[UIImage jm_imageWithRoundedCornersAndSize:CGSizeMake(30, 30) andCornerRadius:15 andColor:RQ_MAIN_BACKGROUNDCOLOR] forState:UIControlStateNormal];
  85. // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
  86. }
  87. break;
  88. }
  89. }
  90. #pragma mark - SystemMethods
  91. - (void)awakeFromNib {
  92. [super awakeFromNib];
  93. // Initialization code
  94. }
  95. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  96. [super setSelected:selected animated:animated];
  97. // Configure the view for the selected state
  98. }
  99. /// type 0对1错2默认3多选题点后后变色 . */
  100. //- (void)setItem:(AnswerItem *)Item {
  101. // _item = Item;
  102. // //0对1错2默认3多选题点后后变色
  103. // if (Item.type == 0) {
  104. // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
  105. //
  106. // }else if (Item.type == 1){
  107. // self.optionLabel.textColor = UIColor.redColor;
  108. //
  109. // }else if (Item.type == 2){//默认和多选取消选中结果后变色
  110. // self.optionLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
  111. // }else if (Item.type == 3){
  112. // self.optionLabel.textColor = RQ_MAIN_COLOR;
  113. // }
  114. // if (Item.picname.length > 1) {
  115. // [self.optionBtn setBackgroundImage:RQImageNamed(Item.picname) forState:UIControlStateNormal];
  116. // [self.optionBtn setTitleNormal:(Item.type == 3)? Item.picname : @""];
  117. // } else {
  118. // [self.optionBtn setBackgroundImage:(Item.type == 3)? [UIImage imageWithColor:RQ_MAIN_COLOR size:CGSizeMake(30, 30)] : RQImageNamed(Item.picname) forState:UIControlStateNormal];
  119. // [self.optionBtn setTitleNormal:Item.picname];
  120. // }
  121. //
  122. // self.optionLabel.text = Item.text;
  123. //}
  124. @end