ContributionListThreeTableViewCell.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // ContributionListThreeTableViewCell.m
  3. // FanweApp
  4. //
  5. // Created by fanwe2014 on 16/6/11.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "ContributionListThreeTableViewCell.h"
  9. @implementation ContributionListThreeTableViewCell
  10. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  11. {
  12. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  13. if (self)
  14. {
  15. _fanweApp = [GlobalVariables sharedInstance];
  16. self.backgroundColor = [UIColor whiteColor];
  17. self.bigHeadView = [[UIImageView alloc]init];
  18. self.smallHeadView = [[UIImageView 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. }
  30. return self;
  31. }
  32. - (void)setCellWithModel:(UserModel *)model withRow:(int)row
  33. {
  34. //排名第几
  35. self.rankingButton.frame = CGRectMake(0, 15, 60, 20);
  36. [self.rankingButton setTitle:[NSString stringWithFormat:@"NO.%d",row] forState:0];
  37. self.rankingButton.titleLabel.font = [UIFont systemFontOfSize:12];
  38. [self.rankingButton setTitleColor:[UIColor blackColor] forState:0];
  39. [self addSubview:self.rankingButton];
  40. //小图
  41. self.smallHeadView.frame = CGRectMake(60,10, 40, 40);
  42. self.smallHeadView.layer.cornerRadius = self.smallHeadView.frame.size.height/2;
  43. self.smallHeadView.layer.masksToBounds = YES;
  44. [self.smallHeadView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:kDefaultPreloadHeadImg];
  45. [self addSubview:self.smallHeadView];
  46. //认证
  47. self.vIconImageView.frame = CGRectMake(CGRectGetMaxX(self.smallHeadView.frame)-15, CGRectGetMaxY(self.smallHeadView.frame)-15, 15, 15);
  48. if (model.v_icon.length > 0) {
  49. self.vIconImageView.hidden = NO;
  50. [self.vIconImageView sd_setImageWithURL:[NSURL URLWithString:model.v_icon]];
  51. }
  52. else
  53. {
  54. self.vIconImageView.hidden = YES;
  55. }
  56. [self addSubview:self.vIconImageView];
  57. //名字
  58. self.nameLabel.textColor = kGrayTransparentColor6;
  59. if (model.nick_name.length < 1)
  60. {
  61. model.nick_name = @"方维";
  62. }
  63. NSString *string = [NSString stringWithFormat:@"%@",model.nick_name];
  64. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:string];
  65. [attr setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13.0]} range:NSMakeRange(0, string.length)];
  66. CGSize size =[string sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}];
  67. if (size.width > kScreenW -CGRectGetMaxX(self.smallHeadView.frame) - 52)
  68. {
  69. size.width = kScreenW -CGRectGetMaxX(self.smallHeadView.frame) - 52 - 10;
  70. self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  71. }
  72. self.nameLabel.frame = CGRectMake(self.smallHeadView.frame.size.width+self.smallHeadView.frame.origin.x+5,10,size.width, 20);
  73. self.nameLabel.attributedText = attr;
  74. [self addSubview:self.nameLabel];
  75. // NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:self.nameLabel.text];
  76. // [attr setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15.0]} range:NSMakeRange(0, self.nameLabel.text.length)];
  77. // CGFloat width =[self.nameLabel.text sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}].width;
  78. // if (width > kScreenW-260)//名字控件需要控制长度
  79. // {
  80. // width = kScreenW - 260-5;
  81. // self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  82. // }
  83. //性别的图片
  84. self.sexImgView.frame = CGRectMake(self.nameLabel.frame.size.width+self.nameLabel.frame.origin.x+5,12, 14, 14);
  85. [self addSubview:self.sexImgView];
  86. if ([model.sex isEqualToString:@"1"])//男
  87. {
  88. self.sexImgView.image = [UIImage imageNamed:@"com_male_selected"];
  89. }
  90. else if ([model.sex isEqualToString:@"2"])//女
  91. {
  92. self.sexImgView.image = [UIImage imageNamed:@"com_female_selected"];
  93. }
  94. //排行版的图片
  95. self.rankingImgView.frame = CGRectMake(self.sexImgView.frame.size.width+self.sexImgView.frame.origin.x+5,12, 28, 14);
  96. self.rankingImgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"rank_%@",model.user_level]];
  97. [self addSubview:self.rankingImgView];
  98. //映票
  99. self.ticketLabel.textColor = textColor4;
  100. self.ticketLabel.font = [UIFont systemFontOfSize:13];
  101. if (model.num.length < 1)
  102. {
  103. model.num = @"0";
  104. }
  105. NSString *string1 = [NSString stringWithFormat:@"贡献 %@ %@",model.num, _fanweApp.appModel.ticket_name];
  106. NSMutableAttributedString *attr1 = [[NSMutableAttributedString alloc] initWithString:string1];
  107. [attr1 setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13.0]} range:NSMakeRange(0, string1.length)];
  108. //CGRect attributeRect1 = [attr boundingRectWithSize:CGSizeMake(kScreenW, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil];多行的
  109. CGSize size1 =[string1 sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}];
  110. [attr1 setAttributes:@{NSForegroundColorAttributeName : kAppGrayColor1} range:[string1 rangeOfString:model.num]];
  111. self.ticketLabel.frame = CGRectMake(self.smallHeadView.frame.size.width+self.smallHeadView.frame.origin.x+5, self.nameLabel.frame.size.height+self.nameLabel.frame.origin.y, size1.width+5, 20);
  112. self.ticketLabel.attributedText = attr1;
  113. [self addSubview:self.ticketLabel];
  114. //底部线
  115. self.view.frame = CGRectMake(10, 59, kScreenW-20, 1);
  116. self.view.backgroundColor = myTextColorLine5;
  117. [self addSubview:self.view];
  118. }
  119. @end