ContributionListTableViewCell.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. //
  2. // ContributionListTableViewCell.m
  3. // FanweApp
  4. //
  5. // Created by fanwe2014 on 16/6/7.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. #import "ContributionListTableViewCell.h"
  8. @implementation ContributionListTableViewCell
  9. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  10. {
  11. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  12. if (self)
  13. {
  14. _fanweApp = [GlobalVariables sharedInstance];
  15. self.backgroundColor = [UIColor whiteColor];
  16. self.bigHeadView = [[UIImageView alloc]init];
  17. self.smallHeadView = [[UIImageView alloc]init];
  18. self.buttonView = [[UIView alloc]init];
  19. self.nameLabel = [[UILabel alloc]init];
  20. self.rankingLabel = [[UILabel alloc]init];
  21. self.smallImgView = [[UIImageView alloc]init];
  22. self.ticketLabel = [[UILabel alloc]init];
  23. self.rankingButton = [UIButton buttonWithType:UIButtonTypeCustom];
  24. self.sexImgView = [[UIImageView alloc]init];
  25. self.rankingImgView = [[UIImageView alloc]init];
  26. self.vIconImageView = [[UIImageView alloc]init];
  27. self.view = [[UIView alloc]init];
  28. self.view.alpha = 0.5;
  29. self.buttonView = [[UIView alloc]init];
  30. self.buttonView.backgroundColor = [UIColor clearColor];
  31. self.buttonView2 = [[UIView alloc]init];
  32. self.buttonView2.backgroundColor = [UIColor clearColor];
  33. }
  34. return self;
  35. }
  36. - (void)setCellWithModel:(UserModel *)model withType:(NSString *)type withNum:(int)num{
  37. if ([type isEqualToString:@"1"])//本次直播
  38. {
  39. self.backgroundColor = kWhiteColor;
  40. self.smallHeadView.hidden = NO;
  41. self.nameLabel.hidden = NO;
  42. //头像
  43. self.smallHeadView.frame = CGRectMake(kScreenW/2-20, 20, 40, 40);
  44. self.smallHeadView.layer.cornerRadius = self.smallHeadView.frame.size.height/2;
  45. self.smallHeadView.layer.masksToBounds = YES;
  46. [self.smallHeadView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:kDefaultPreloadHeadImg];
  47. [self addSubview:self.smallHeadView];
  48. //认证
  49. self.vIconImageView.frame = CGRectMake(CGRectGetMaxX(self.smallHeadView.frame)-15, CGRectGetMaxY(self.smallHeadView.frame)-15, 15, 15);
  50. if (model.v_icon.length > 0) {
  51. self.vIconImageView.hidden = NO;
  52. [self.vIconImageView sd_setImageWithURL:[NSURL URLWithString:model.v_icon]];
  53. }
  54. else
  55. {
  56. self.vIconImageView.hidden = YES;
  57. }
  58. [self addSubview:self.vIconImageView];
  59. //名字
  60. self.nameLabel.frame = CGRectMake(0,self.smallHeadView.frame.size.height+self.smallHeadView.frame.origin.y, kScreenW, 20);
  61. self.nameLabel.font = [UIFont systemFontOfSize:15];
  62. self.nameLabel.textColor = textColor4;
  63. self.nameLabel.textAlignment = NSTextAlignmentCenter;
  64. if (model.nick_name.length < 1)
  65. {
  66. model.nick_name = @"方维";
  67. }
  68. self.nameLabel.text = model.nick_name;
  69. NSString *nameString = [NSString stringWithFormat:@"%@",model.nick_name];
  70. NSMutableAttributedString *attr1 = [[NSMutableAttributedString alloc] initWithString:nameString];
  71. [attr1 setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15.0]} range:NSMakeRange(0, nameString.length)];
  72. self.nameLabel.attributedText = attr1;
  73. [self addSubview:self.nameLabel];
  74. //图片
  75. self.smallImgView.frame = CGRectMake(0, 3, 18, 19);
  76. self.smallImgView.image = [UIImage imageNamed:@"me_ranking_yingpiao"];
  77. //映票
  78. //self.ticketLabel.frame = CGRectMake(kScreenW/2-25, self.nameLabel.frame.size.height+self.nameLabel.frame.origin.y, 150, 25);
  79. self.ticketLabel.textAlignment = NSTextAlignmentLeft;
  80. self.ticketLabel.font = [UIFont systemFontOfSize:15];
  81. self.ticketLabel.textColor = textColor4;
  82. if (model.ticket.length < 1)
  83. {
  84. model.ticket = @"0";
  85. }
  86. self.ticketLabel.font = [UIFont systemFontOfSize:15];
  87. // NSString *string = [NSString stringWithFormat:@"%@ %@",model.ticket, _fanweApp.appModel.ticket_name];
  88. NSString *string = [NSString stringWithFormat:@"%d %@",num, _fanweApp.appModel.ticket_name];
  89. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:string];
  90. [attr setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15.0]} range:NSMakeRange(0, string.length)];
  91. [attr setAttributes:@{NSForegroundColorAttributeName : kAppGrayColor1} range:[string rangeOfString:model.ticket]]; //设置会员名称的字体颜色
  92. CGFloat width =[string sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}].width;
  93. self.buttonView.frame = CGRectMake(kScreenW/2-(24+width)/2, self.nameLabel.frame.size.height+self.nameLabel.frame.origin.y, width, 25);
  94. [self addSubview:self.buttonView];
  95. self.ticketLabel.frame = CGRectMake(21, 0, width, 25);
  96. self.ticketLabel.attributedText = attr;
  97. [self.buttonView addSubview:self.ticketLabel];
  98. [self.buttonView addSubview:self.smallImgView];
  99. }else if ([type isEqualToString:@"0"])//累计直播
  100. {
  101. self.smallHeadView.hidden = YES;
  102. self.nameLabel.hidden = YES;
  103. self.vIconImageView.hidden = YES;
  104. self.smallImgView.frame = CGRectMake(0, 20, 18, 19);
  105. self.smallImgView.image = [UIImage imageNamed:@"me_ranking_yingpiao"];
  106. //映票
  107. self.ticketLabel.textAlignment = NSTextAlignmentLeft;
  108. self.ticketLabel.font = [UIFont systemFontOfSize:15];
  109. self.ticketLabel.textColor = textColor4;
  110. self.ticketLabel.font = [UIFont systemFontOfSize:15];
  111. // NSString *string = [NSString stringWithFormat:@"%@ %@",model.ticket, _fanweApp.appModel.ticket_name];
  112. NSString *string = [NSString stringWithFormat:@"%d %@",num, _fanweApp.appModel.ticket_name];
  113. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:string];
  114. [attr setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15.0]} range:NSMakeRange(0, string.length)];
  115. [attr setAttributes:@{NSForegroundColorAttributeName : kAppGrayColor1} range:[string rangeOfString:[NSString stringWithFormat:@"%d",num]]]; //设置会员名称的字体颜色
  116. CGFloat width =[string sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}].width;
  117. self.buttonView.frame = CGRectMake(kScreenW/2-(24+width)/2,0,width, 50);
  118. [self addSubview:self.buttonView];
  119. self.ticketLabel.frame = CGRectMake(21, 17, width, 25);
  120. self.ticketLabel.attributedText = attr;
  121. [self.buttonView addSubview:self.ticketLabel];
  122. [self.buttonView addSubview:self.smallImgView];
  123. self.backgroundColor = kBackGroundColor;
  124. }
  125. }
  126. - (void)setCellWithModel:(UserModel *)model withRow:(int)row
  127. {
  128. self.smallHeadView.hidden = NO;
  129. self.nameLabel.hidden = NO;
  130. self.backgroundColor = kWhiteColor;
  131. if (row == 1)
  132. {
  133. //排名第几
  134. self.rankingButton.frame = CGRectMake(0, 30, 54, 20);
  135. [self.rankingButton setImage:[UIImage imageNamed:@"me_yp_bg2"] forState:0];
  136. self.rankingLabel.frame = CGRectMake(0, 0, 54, 20);
  137. self.rankingLabel.backgroundColor = [UIColor clearColor];
  138. self.rankingLabel.textAlignment = NSTextAlignmentCenter;
  139. self.rankingLabel.text = @"NO.1";
  140. self.rankingLabel.textColor = [UIColor whiteColor];
  141. self.rankingLabel.font = [UIFont systemFontOfSize:13];
  142. [self addSubview:self.rankingButton];
  143. [self.rankingButton addSubview:self.rankingLabel];
  144. //小图
  145. self.smallHeadView.frame = CGRectMake(kScreenW/2-26, 24, 48, 48);
  146. self.smallHeadView.layer.cornerRadius = self.smallHeadView.frame.size.height/2;
  147. self.smallHeadView.layer.masksToBounds = YES;
  148. [self.smallHeadView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:kDefaultPreloadHeadImg];
  149. [self addSubview:self.smallHeadView];
  150. //大图
  151. self.bigHeadView.frame = CGRectMake(kScreenW/2-51, 10, 96, 71);
  152. self.bigHeadView.image = [UIImage imageNamed:@"me_yp_no_1"];
  153. [self addSubview:self.bigHeadView];
  154. //认证
  155. self.vIconImageView.frame = CGRectMake(CGRectGetMaxX(self.smallHeadView.frame)-15, CGRectGetMaxY(self.smallHeadView.frame)-15, 15, 15);
  156. if (model.v_icon.length > 0) {
  157. self.vIconImageView.hidden = NO;
  158. [self.vIconImageView sd_setImageWithURL:[NSURL URLWithString:model.v_icon]];
  159. }
  160. else
  161. {
  162. self.vIconImageView.hidden = YES;
  163. }
  164. [self addSubview:self.vIconImageView];
  165. //名字
  166. if (model.nick_name.length < 1)
  167. {
  168. model.nick_name = @"方维";
  169. }
  170. NSString *string = [NSString stringWithFormat:@"%@",model.nick_name];
  171. self.nameLabel.textColor = kGrayTransparentColor6;
  172. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:string];
  173. [attr setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15.0]} range:NSMakeRange(0, string.length)];
  174. CGFloat width =[string sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}].width;
  175. self.buttonView2.frame = CGRectMake(kScreenW/2-(width+52)/2, self.bigHeadView.frame.size.height+ self.bigHeadView.frame.origin.y+8, width+52, 20);
  176. [self addSubview:self.buttonView2];
  177. self.nameLabel.frame = CGRectMake(0, 0,width, 20);
  178. self.nameLabel.textColor = textColor4;
  179. self.nameLabel.attributedText = attr;
  180. [self.buttonView2 addSubview:self.nameLabel];
  181. //性别的图片
  182. self.sexImgView.frame = CGRectMake(width+5,3, 14, 14);
  183. if ([model.sex isEqualToString:@"1"])
  184. {
  185. self.sexImgView.image = [UIImage imageNamed:@"com_male_selected"];
  186. }else{
  187. self.sexImgView.image = [UIImage imageNamed:@"com_female_selected"];
  188. }
  189. [self.buttonView2 addSubview:self.sexImgView];
  190. //排行版的图片
  191. self.rankingImgView.frame = CGRectMake(self.sexImgView.frame.size.width+self.sexImgView.frame.origin.x+5,3, 28, 14);
  192. if ([model.user_level integerValue] < 1)
  193. {
  194. model.user_level = @"1";
  195. }
  196. self.rankingImgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"rank_%@",model.user_level]];
  197. [self.buttonView2 addSubview:self.rankingImgView];
  198. //映票
  199. self.ticketLabel.textColor = textColor4;
  200. if (model.num.length < 1)
  201. {
  202. model.num = @"0";
  203. }
  204. self.ticketLabel.font = [UIFont systemFontOfSize:15];
  205. NSString *string1 = [NSString stringWithFormat:@"贡献 %@ %@",model.num, _fanweApp.appModel.ticket_name];
  206. NSMutableAttributedString *attr1 = [[NSMutableAttributedString alloc] initWithString:string1];
  207. [attr1 setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15.0]} range:NSMakeRange(0, string1.length)];
  208. //CGRect attributeRect1 = [attr boundingRectWithSize:CGSizeMake(kScreenW, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil]; 多行的
  209. CGSize size1 =[string1 sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}];
  210. [attr1 setAttributes:@{NSForegroundColorAttributeName : kAppGrayColor1} range:[string1 rangeOfString:model.num]];
  211. self.ticketLabel.frame = CGRectMake(kScreenW/2-size1.width/2, self.buttonView2.frame.size.height+self.buttonView2.frame.origin.y+6, size1.width+5, 20);
  212. self.ticketLabel.attributedText = attr1;
  213. [self addSubview:self.ticketLabel];
  214. //底部线
  215. self.view.frame = CGRectMake(10, 146, kScreenW-20, 1);
  216. self.view.backgroundColor = myTextColorLine5;;
  217. [self addSubview:self.view];
  218. }
  219. }
  220. - (void)awakeFromNib
  221. {
  222. [super awakeFromNib];
  223. }
  224. @end