XYModifyAnswerTableViewCell.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. //
  2. // XYModifyInputTextTableViewCell.m
  3. // Timi
  4. //
  5. // Created by gy on 2021/3/4.
  6. //
  7. #import "XYModifyAnswerTableViewCell.h"
  8. #import "XYModifyUserInfoListModel.h"
  9. #import "XYModifyAnswerQuestionViewController.h"
  10. @interface XYModifyAnswerTableViewCell (){
  11. }
  12. @property (nonatomic, strong) UIImageView *questionImgView;
  13. @property (nonatomic, strong) UILabel *questionLab;
  14. @property (nonatomic, strong) UIImageView *answerImgView;
  15. @property (nonatomic, strong) UILabel *answerLab;
  16. @property (nonatomic, strong) UIView *withoutView;
  17. @property (nonatomic, strong) UIImageView *moreImageView;
  18. @property (nonatomic, strong) XYModifyUserInfoListModel *model;
  19. @end
  20. @implementation XYModifyAnswerTableViewCell
  21. #pragma mark - Public Method
  22. + (instancetype)cellWithTableView:(UITableView *)tableView {
  23. static NSString * const cellId = @"XYModifyAnswerTableViewCell";
  24. XYModifyAnswerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  25. if (cell == nil) {
  26. cell = [[XYModifyAnswerTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  27. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  28. }
  29. return cell;
  30. }
  31. - (void)configureModel:(XYModifyUserInfoListModel *)model {
  32. self.model = model;
  33. // if (StringIsEmpty(model.itemValue)) {
  34. // self.withoutView.hidden = NO;
  35. // self.questionImgView.hidden = YES;
  36. // self.questionLab.hidden = YES;
  37. // self.answerImgView.hidden = YES;
  38. // self.answerLab.hidden = YES;
  39. // }else{
  40. self.withoutView.hidden = YES;
  41. self.questionImgView.hidden = NO;
  42. self.questionLab.hidden = NO;
  43. self.answerImgView.hidden = NO;
  44. self.answerLab.hidden = NO;
  45. self.questionImgView.image = [UIImage imageNamed:@"icon_user_question"];
  46. self.questionLab.text = model.itemName;
  47. self.answerImgView.image = [UIImage imageNamed:@"icon_user_answer"];
  48. self.answerLab.text = model.itemValue;
  49. // }
  50. if (model.userInfoType == ModifyUserInfo_Type_Main) {
  51. self.moreImageView.hidden = YES;
  52. }else{
  53. self.moreImageView.hidden = NO;
  54. }
  55. }
  56. #pragma mark - 初始化
  57. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  58. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  59. // 初始化
  60. [self _setup];
  61. }
  62. return self;
  63. }
  64. #pragma mark - 事件处理Or辅助方法
  65. - (void)withoutViewAction{
  66. XYModifyAnswerQuestionViewController *controller = XYModifyAnswerQuestionViewController.new;
  67. controller.model = self.model;
  68. [self.viewController.navigationController pushViewController:controller animated:YES];
  69. }
  70. #pragma mark - Private Method
  71. - (void)_setup{
  72. self.backgroundColor = Color_White;
  73. }
  74. - (UIImageView *)questionImgView{
  75. if (_questionImgView == nil) {
  76. _questionImgView = [[UIImageView alloc] init];
  77. _questionImgView.contentMode = UIViewContentModeScaleAspectFill;
  78. [self.contentView addSubview:_questionImgView];
  79. [_questionImgView mas_makeConstraints:^(MASConstraintMaker *make) {;
  80. make.left.equalTo(self.contentView.mas_left).offset(20);
  81. make.top.equalTo(self.contentView.mas_top).offset(8);
  82. make.width.offset(16);
  83. make.height.offset(16);
  84. }];
  85. [_questionImgView layoutIfNeeded];
  86. }
  87. return _questionImgView;
  88. }
  89. - (UILabel *)questionLab{
  90. if (_questionLab == nil) {
  91. _questionLab = [[UILabel alloc] init];
  92. _questionLab.text = @" ";
  93. _questionLab.textAlignment = NSTextAlignmentLeft;
  94. _questionLab.textColor = [UIColor colorWithHexString:@"#303133" alpha:1];
  95. _questionLab.font = [UIFont fontWithName:kPFSCFont size:14];
  96. _questionLab.numberOfLines = 0;
  97. [_questionLab sizeToFit];
  98. [self.contentView addSubview:_questionLab];
  99. [_questionLab mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.left.equalTo(self.questionImgView.mas_right).offset(8);
  101. make.right.equalTo(self.contentView.mas_right).offset(-40);
  102. make.top.equalTo(self.questionImgView.mas_top).offset(-2);
  103. }];
  104. [_questionLab layoutIfNeeded];
  105. }
  106. return _questionLab;
  107. }
  108. - (UIImageView *)answerImgView{
  109. if (_answerImgView == nil) {
  110. _answerImgView = [[UIImageView alloc] init];
  111. _answerImgView.contentMode = UIViewContentModeScaleAspectFill;
  112. [self.contentView addSubview:_answerImgView];
  113. [_answerImgView mas_makeConstraints:^(MASConstraintMaker *make) {;
  114. make.left.equalTo(self.contentView.mas_left).offset(20);
  115. make.top.equalTo(self.questionLab.mas_bottom).offset(6);
  116. make.width.offset(16);
  117. make.height.offset(16);
  118. }];
  119. [_answerImgView layoutIfNeeded];
  120. }
  121. return _answerImgView;
  122. }
  123. - (UILabel *)answerLab{
  124. if (_answerLab == nil) {
  125. _answerLab = [[UILabel alloc] init];
  126. _answerLab.text = @" ";
  127. _answerLab.textAlignment = NSTextAlignmentLeft;
  128. _answerLab.textColor = [UIColor colorWithHexString:@"#606266" alpha:1];
  129. _answerLab.font = [UIFont fontWithName:kPFSCFont size:14];
  130. _answerLab.numberOfLines = 0;
  131. [_answerLab sizeToFit];
  132. [self.contentView addSubview:_answerLab];
  133. [_answerLab mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.left.equalTo(self.answerImgView.mas_right).offset(8);
  135. make.right.equalTo(self.contentView.mas_right).offset(-40);
  136. make.top.equalTo(self.answerImgView.mas_top).offset(-2);
  137. }];
  138. [_answerLab layoutIfNeeded];
  139. }
  140. return _answerLab;
  141. }
  142. - (UIView *)withoutView{
  143. if (_withoutView == nil) {
  144. _withoutView = [[UIView alloc] init];
  145. _withoutView.backgroundColor = [UIColor clearColor];
  146. [self.contentView addSubview:_withoutView];
  147. [_withoutView mas_makeConstraints:^(MASConstraintMaker *make) {
  148. make.edges.equalTo(self.contentView);
  149. }];
  150. [_withoutView layoutIfNeeded];
  151. UIImageView *imgView = [[UIImageView alloc] init];
  152. imgView.image = [UIImage imageNamed:@"icon_nodata_answer"];
  153. imgView.contentMode = UIViewContentModeScaleAspectFill;
  154. [_withoutView addSubview:imgView];
  155. [imgView mas_makeConstraints:^(MASConstraintMaker *make) {;
  156. make.top.equalTo(_withoutView.mas_top).offset(15);
  157. make.centerX.equalTo(_withoutView.mas_centerX).offset(0);
  158. make.width.offset(120);
  159. make.height.offset(120);
  160. }];
  161. [imgView layoutIfNeeded];
  162. UILabel *_titlelab = [[UILabel alloc] init];
  163. _titlelab.text = @"添加你感兴趣的问答,让Ta更了解你";
  164. _titlelab.textAlignment = NSTextAlignmentLeft;
  165. _titlelab.textColor = [UIColor colorWithHexString:@"#303133" alpha:1];
  166. _titlelab.font = [UIFont fontWithName:kPFSCFont size:14];
  167. [_titlelab sizeToFit];
  168. [_withoutView addSubview:_titlelab];
  169. [_titlelab mas_makeConstraints:^(MASConstraintMaker *make) {
  170. make.centerX.equalTo(_withoutView.mas_centerX).offset(0);
  171. make.top.equalTo(imgView.mas_bottom).offset(20);
  172. }];
  173. [_titlelab layoutIfNeeded];
  174. UILabel *btnLab = [[UILabel alloc] init];
  175. btnLab.text = @"+ 添加问答";
  176. btnLab.textAlignment = NSTextAlignmentCenter;
  177. btnLab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1];
  178. btnLab.font = [UIFont fontWithName:kPFSCFont size:14];
  179. btnLab.backgroundColor = [UIColor colorGradientChangeWithSize:CGSizeMake(110, 40.0f) direction:GradientChangeDirectionLevel startColor:ColorFromHexString(@"#5D26FF") endColor:ColorFromHexString(@"#9059FF")];
  180. [btnLab sizeToFit];
  181. [_withoutView addSubview:btnLab];
  182. [btnLab mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.centerX.equalTo(_withoutView.mas_centerX).offset(0);
  184. make.top.equalTo(_titlelab.mas_bottom).offset(18);
  185. make.width.offset(110);
  186. make.height.offset(40);
  187. }];
  188. [btnLab layoutIfNeeded];
  189. kViewRadius(btnLab, 20);
  190. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(withoutViewAction)];
  191. _withoutView.userInteractionEnabled = YES;
  192. [_withoutView addGestureRecognizer:tap];
  193. }
  194. return _withoutView;
  195. }
  196. - (UIImageView *)moreImageView{
  197. if (_moreImageView == nil) {
  198. _moreImageView = [[UIImageView alloc] init];
  199. _moreImageView.image = arrowMore();
  200. _moreImageView.contentMode = UIViewContentModeScaleAspectFill;
  201. [self.contentView addSubview:_moreImageView];
  202. [_moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {;
  203. [self.moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  204. make.right.equalTo(self.contentView).offset(-SPACING_EDGE);
  205. make.top.equalTo(self.questionImgView.mas_bottom).offset(0);
  206. make.width.equalTo(@6.0f);
  207. make.height.equalTo(@10.0f);
  208. }];
  209. }];
  210. [_moreImageView layoutIfNeeded];
  211. }
  212. return _moreImageView;
  213. }
  214. - (void)awakeFromNib {
  215. [super awakeFromNib];
  216. // Initialization code
  217. }
  218. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  219. [super setSelected:selected animated:animated];
  220. // Configure the view for the selected state
  221. }
  222. @end