ChargerTableViewCell.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // ChargerTableViewCell.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 2016/11/24.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "ChargerTableViewCell.h"
  9. #import "LiveDataModel.h"
  10. @implementation ChargerTableViewCell
  11. - (void)awakeFromNib
  12. {
  13. [super awakeFromNib];
  14. self.BuguLive =[GlobalVariables sharedInstance];
  15. self.headImgView.layer.cornerRadius = 25;
  16. self.headImgView.layer.masksToBounds = YES;
  17. self.lineView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.headImgView.frame)+10, self.frame.size.height-1, kScreenW-CGRectGetMaxX(self.headImgView.frame)-10, 1)];
  18. self.lineView.backgroundColor = kAppSpaceColor4;
  19. [self addSubview:self.lineView];
  20. self.timeLabel.textColor = kAppGrayColor2;
  21. self.moneyLabel.textColor = kAppGrayColor2;
  22. self.lookLabel.textColor = kAppGrayColor2;
  23. self.nameLabel.textColor = kAppGrayColor1;
  24. }
  25. - (void)setCellWithDict:(LiveDataModel *)model andType:(int)type andLive_pay_type:(int)live_pay_type
  26. {
  27. [self.headImgView sd_setImageWithURL:[NSURL URLWithString:model.head_image]];
  28. NSString *nameString;
  29. if (model.nick_name.length < 1)
  30. {
  31. nameString = ASLocalizedString(@"暂时还未命名");
  32. }else
  33. {
  34. nameString = model.nick_name;
  35. }
  36. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:nameString];
  37. [attr setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15.0]} range:NSMakeRange(0, nameString.length)];
  38. CGFloat width =[nameString sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}].width;
  39. if (width+5 > kScreenW-130)//名字控件需要控制长度
  40. {
  41. width = kScreenW - 135;
  42. self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  43. }
  44. self.nameLabel.frame = CGRectMake(70, 11, width, 21);
  45. self.sexImgView.frame = CGRectMake(width+75, 14, 14, 14);
  46. self.rankImgView.frame = CGRectMake(width+94, 13, 28, 16);
  47. self.nameLabel.attributedText = attr;
  48. if ([model.sex isEqualToString:@"1"])
  49. {
  50. self.sexImgView.image = [UIImage imageNamed:@"com_male_selected"];
  51. }else if([model.sex isEqualToString:@"2"])
  52. {
  53. self.sexImgView.image = [UIImage imageNamed:@"com_female_selected"];
  54. }
  55. self.rankImgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"level%@",model.user_level]];
  56. if (type == 0)
  57. {
  58. self.moneyLabel.text = [NSString stringWithFormat:ASLocalizedString(@"消费%@:%@"),self.BuguLive.appModel.diamond_name,[self checkDiamondNum:model.total_diamonds]];
  59. }else
  60. {
  61. self.moneyLabel.text = [NSString stringWithFormat:ASLocalizedString(@"贡献%@:%@"),self.BuguLive.appModel.diamond_name,[self checkDiamondNum:model.total_diamonds]];
  62. }
  63. self.lookLabel.text = [NSString stringWithFormat:ASLocalizedString(@"开始观看时间:%@"),model.start_time];
  64. if (live_pay_type == 1)
  65. {
  66. self.timeLabel.hidden = YES;
  67. }else
  68. {
  69. self.timeLabel.hidden = NO;
  70. self.timeLabel.text = [NSString stringWithFormat:ASLocalizedString(@"观看时长:%@"),model.total_time_format];
  71. }
  72. }
  73. -(NSString *)checkDiamondNum:(NSString *)num{
  74. NSString *numStr = @"";
  75. float numF = num.floatValue;
  76. if (numF > 1000) {
  77. numStr = [NSString stringWithFormat:@"%.1fK",floorf(numF/1000)];
  78. // [NSString stringWithFormat:@"%.2f",num.floatValue];
  79. }else{
  80. numStr = [NSString stringWithFormat:@"%.0f",numF];
  81. }
  82. return numStr;
  83. }
  84. @end