EvaListCell.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // EvaListCell.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/5/31.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. /*
  9. COACHNAME = "\U8096\U6c89\U4eae";
  10. SCHOOLNAME = "\U6c88\U9633\U5e02\U516b\U68f5\U6811\U6c7d\U8f66\U9a7e\U9a76\U5458\U57f9\U8bad\U6709\U9650\U516c\U53f8";
  11. SHORTNAME = "\U516b\U68f5\U6811\U9a7e\U6821";
  12. SRVMANNER = "";srvmanner
  13. STAR = 5;
  14. SUBJECT = 2;
  15. TEACHLEVEL = "\U6960\U54e5\U5a01\U6b66";
  16. TIME = "2017-04-21";
  17. "TSO_NAME" = "\U6c5f\U6587\U6df3";
  18. */
  19. #import "EvaListCell.h"
  20. #import "NSString+ex.h"
  21. #import "RatingBar.h"
  22. @interface EvaListCell()
  23. {
  24. UILabel *_coach;
  25. UILabel *_school;
  26. UILabel *_srvmanner;
  27. UILabel *_star;
  28. UILabel *_subject;
  29. UILabel *_teachLevel;
  30. UILabel *_student;
  31. UILabel *_time;
  32. UIView *_view;
  33. RatingBar *_starBar;
  34. UIView * _srvmannerView;
  35. }
  36. @end
  37. @implementation EvaListCell
  38. +(EvaListCell *)cellForTabelView:(UITableView *)tableView{
  39. EvaListCell* cell = [tableView dequeueReusableCellWithIdentifier:@"EvaListCell"];
  40. if (!cell) {
  41. cell = [[EvaListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EvaListCell"];
  42. }
  43. return cell;
  44. }
  45. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  46. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  47. self.selectionStyle = UITableViewCellSelectionStyleNone;
  48. NSArray * textArr = @[@"教练名字",@"机构名字",@"srvmanner",@"星级",@"科目",@"评价内容",@"时间",@"学员"];
  49. NSMutableArray * labArr = [NSMutableArray new];
  50. //
  51. for (int i=0; i<textArr.count; i++) {
  52. UILabel * lab = [[UILabel alloc]init];
  53. lab.textColor = [UIColor blackColor];
  54. lab.textAlignment = NSTextAlignmentLeft;
  55. lab.font = [UIFont systemFontOfSize:14];
  56. [self.contentView addSubview:lab];
  57. [labArr addObject:lab];
  58. }
  59. _coach = labArr[0];
  60. _school = labArr[1];
  61. _srvmanner = labArr[2];
  62. _star = labArr[3];
  63. _subject = labArr[4];
  64. _teachLevel = labArr[5];
  65. _time = labArr[6];
  66. _student = labArr[7];
  67. _time.textAlignment = NSTextAlignmentRight;
  68. _time.textColor = [UIColor lightGrayColor];
  69. _time.font = [UIFont systemFontOfSize:12];
  70. _teachLevel.numberOfLines = 0;
  71. _srvmanner.numberOfLines = 0;
  72. _subject.textAlignment = NSTextAlignmentRight;
  73. _starBar = [[RatingBar alloc]initWithFrame:CGRectMake(0, 0, 70, 17) Flag:YES];
  74. _starBar.enable = NO;
  75. [self.contentView addSubview:_starBar];
  76. //
  77. _view = [UIView new];
  78. _view.backgroundColor = KBackGroundColor;
  79. [self.contentView addSubview:_view];
  80. //
  81. _srvmannerView = [UIView new];
  82. [self.contentView addSubview:_srvmannerView];
  83. }
  84. return self;
  85. }
  86. - (void)layoutSubviews {
  87. [super layoutSubviews];
  88. [super layoutSubviews];
  89. CGFloat wid = self.width;
  90. CGFloat x,y,w,h,bd;
  91. x = 0;
  92. w = wid;
  93. y = 0;
  94. h = 20;
  95. _view.frame = setDIYFrame;
  96. y += 5;
  97. x = 20;
  98. y += h;
  99. bd = 5;
  100. w = wid - 40;
  101. h = [_coach.text heightForWid:w Font:14];
  102. if (h != 0) {
  103. y += bd;
  104. }
  105. _coach.frame = setDIYFrame;
  106. _time.frame = setDIYFrame;
  107. y += h+bd;
  108. h = 17;
  109. _school.frame = setDIYFrame;
  110. if (_time.frame.size.height == 0) {
  111. _time.frame = setDIYFrame;
  112. }
  113. y += h;
  114. h = [_teachLevel.text heightForWid:w Font:14];
  115. if (h != 0) {
  116. y += bd;
  117. }
  118. _teachLevel.frame = setDIYFrame;
  119. y += h;
  120. if (_srvmanner.text.length != 0) {
  121. y += bd;
  122. h = 17;
  123. }else{
  124. h = 0;
  125. }
  126. _srvmannerView.frame = setDIYFrame;
  127. y += h+bd;
  128. h = 17;
  129. _subject.frame = setDIYFrame;
  130. w = 70;
  131. _star.frame = setDIYFrame;
  132. x += w;
  133. y += 3;
  134. w = 80;
  135. _starBar.frame = setDIYFrame;
  136. // y += h;
  137. // _student.frame = setDIYFrame;
  138. }
  139. - (void)updateWithDic:(NSDictionary *)dic {
  140. //NSArray * textArr = @[@"教练名字",@"机构名字",@"srvmanner",@"星级",@"科目",@"评价内容",@"时间",@"学员"];
  141. if ([dic[@"COACHNAME"] length] != 0) {
  142. _coach.text = [NSString stringWithFormat:@"被评价教练 :%@",dic[@"COACHNAME"]];
  143. _school.text = [NSString stringWithFormat:@"所属驾校 :%@",dic[@"SHORTNAME"]];
  144. }else{
  145. _coach.text = @"";
  146. _school.text = [NSString stringWithFormat:@"被评价驾校 :%@",dic[@"SHORTNAME"]];
  147. }
  148. for (UIView * subV in _srvmannerView.subviews) {
  149. [subV removeFromSuperview];
  150. }
  151. if ([dic[@"SRVMANNER"] length] != 0) {
  152. _srvmanner.text = dic[@"SRVMANNER"];
  153. NSArray * array = [dic[@"SRVMANNER"] componentsSeparatedByString:@","];
  154. [self createLabViewsWithArray:array];
  155. }else{
  156. _srvmanner.text = @"";
  157. }
  158. if ([dic[@"TEACHLEVEL"] length] != 0) {
  159. _teachLevel.text = [NSString stringWithFormat:@"评价内容 :%@",dic[@"TEACHLEVEL"]];
  160. }else{
  161. _teachLevel.text = @"";
  162. }
  163. _star.text = [NSString stringWithFormat:@"评价星级 :"];
  164. _starBar.starNumber = [[NSString stringWithFormat:@"%@",dic[@"STAR"]] integerValue];
  165. NSString * kemu = @"";
  166. switch ([[NSString stringWithFormat:@"%@",dic[@"SUBJECT"]] integerValue]) {
  167. case 1:
  168. kemu = @"一";
  169. break;
  170. case 2:
  171. kemu = @"二";
  172. break;
  173. case 3:
  174. kemu = @"三";
  175. break;
  176. case 4:
  177. kemu = @"四";
  178. break;
  179. default:
  180. break;
  181. }
  182. _subject.text = [NSString stringWithFormat:@"培训科目 :科目%@",kemu];
  183. _time.text = [NSString stringWithFormat:@"%@",dic[@"TIME"]];
  184. _student.text = [NSString stringWithFormat:@"学员 :%@",dic[@"TSO_NAME"]];
  185. }
  186. -(void)createLabViewsWithArray:(NSArray *)array{
  187. //lableview
  188. UILabel * lable;
  189. CGFloat x = 0;
  190. CGFloat y = 0;
  191. CGFloat w = 0;
  192. CGFloat h = 17;
  193. CGFloat bd = 20;
  194. for (int i=0;i<array.count;i++) {
  195. NSString * contentStr = array[i];
  196. CGSize size =[contentStr sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}];
  197. w = size.width;
  198. lable = [[UILabel alloc]KSetxywh];
  199. x += bd+w;
  200. lable .text = contentStr;
  201. lable.textColor = COLOR_THEME;
  202. lable.font = [UIFont systemFontOfSize:13];
  203. lable.textAlignment = NSTextAlignmentCenter;
  204. lable.layer.borderWidth = 0.5;
  205. lable.layer.borderColor = COLOR_THEME.CGColor;
  206. [_srvmannerView addSubview:lable];
  207. }
  208. }
  209. - (void)awakeFromNib {
  210. [super awakeFromNib];
  211. // Initialization code
  212. }
  213. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  214. [super setSelected:selected animated:animated];
  215. // Configure the view for the selected state
  216. }
  217. @end