ContributionListTwoTableViewCell.m 10 KB

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