RechargeDesCell.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // RechargeDesCell.m
  3. // BuguLive
  4. //
  5. // Created by 王珂 on 17/3/13.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "RechargeDesCell.h"
  9. @interface RechargeDesCell()
  10. @end
  11. @implementation RechargeDesCell
  12. - (instancetype)initWithFrame:(CGRect)frame
  13. {
  14. if (self = [super initWithFrame:frame]) {
  15. _rechargeView = [[UIView alloc] init];
  16. [self.contentView addSubview:_rechargeView];
  17. _numberLabel = [[UILabel alloc] init];
  18. _numberLabel.font = kAppMiddleTextFont;
  19. _numberLabel.textColor = kAppGrayColor1;
  20. [_rechargeView addSubview:_numberLabel];
  21. _diamondImageView = [[UIImageView alloc] init];
  22. _diamondImageView.image = [UIImage imageNamed:@"com_diamond_1"];
  23. _diamondImageView.contentMode = UIViewContentModeScaleAspectFit;
  24. [_rechargeView addSubview:_diamondImageView];
  25. _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 25, self.width, 15)];
  26. _priceLabel.font = kAppSmallTextFont;
  27. _priceLabel.textColor = kAppGrayColor3;
  28. _priceLabel.text = ASLocalizedString(@"售价:0.01");
  29. _priceLabel.textAlignment = NSTextAlignmentCenter;
  30. [self.contentView addSubview:_priceLabel];
  31. _gameCoinLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 45,self.width , 15)];
  32. _gameCoinLabel.font = kAppSmallTextFont;
  33. _gameCoinLabel.textColor = kAppGrayColor3;
  34. _gameCoinLabel.textAlignment = NSTextAlignmentCenter;
  35. _gameCoinLabel.text = ASLocalizedString(@"赠送10000游戏币");
  36. [self.contentView addSubview:_gameCoinLabel];
  37. _otherPayLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (self.height-15)/2, self.width, 15)];
  38. _otherPayLabel.textAlignment = NSTextAlignmentCenter;
  39. _otherPayLabel.text = ASLocalizedString(@"输入其它金额");
  40. _otherPayLabel.font = kAppMiddleTextFont;
  41. _otherPayLabel.textColor = kAppGrayColor3;
  42. _otherPayLabel.hidden = YES;
  43. [self.contentView addSubview:_otherPayLabel];
  44. self.contentView.backgroundColor = [UIColor whiteColor];
  45. self.contentView.layer.cornerRadius = 5;
  46. self.contentView.layer.masksToBounds = YES;
  47. self.contentView.layer.borderColor = kAppGrayColor1.CGColor;
  48. self.contentView.layer.borderWidth = 1.0;
  49. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickCell)];
  50. [self addGestureRecognizer:tap];
  51. }
  52. return self;
  53. }
  54. - (void)setModel:(PayMoneyModel *)model
  55. {
  56. _model = model;
  57. for (UIView *view in self.contentView.subviews) {
  58. view.hidden = YES;
  59. }
  60. if (model.hasOtherPay) {
  61. _otherPayLabel.hidden = NO;
  62. }
  63. else
  64. {
  65. NSString * str = [NSString stringWithFormat:@"%zd",self.model.diamonds];
  66. CGSize priceSize = [str boundingRectWithSize:CGSizeMake(MAXFLOAT, self.width) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:kAppMiddleTextFont} context:nil].size;
  67. CGFloat length = priceSize.width+17;
  68. _rechargeView.hidden = NO;
  69. _numberLabel.hidden = NO;
  70. _diamondImageView.hidden = NO;
  71. if (model.gift_coins_des.length>0) {
  72. _rechargeView.frame = CGRectMake((self.width-length)/2, 5, length, 15);
  73. _priceLabel.frame = CGRectMake(0, 25, self.width, 15);
  74. _gameCoinLabel.frame = CGRectMake(0, 45, self.width, 15);
  75. _priceLabel.hidden = NO;
  76. _gameCoinLabel.text = [NSString stringWithFormat:@"%@",model.gift_coins_des];
  77. _gameCoinLabel.hidden = NO;
  78. }
  79. else
  80. {
  81. _rechargeView.frame = CGRectMake((self.width-length)/2, 15, length, 15);
  82. _priceLabel.frame = CGRectMake(0, 35, self.width, 15);
  83. _priceLabel.hidden = NO;
  84. }
  85. _numberLabel.frame = CGRectMake(0, 0, priceSize.width, 15);
  86. _diamondImageView.frame = CGRectMake(CGRectGetMaxX(_numberLabel.frame)+2,0, 15, 15);
  87. _numberLabel.text = str;
  88. _priceLabel.text = [NSString stringWithFormat:ASLocalizedString(@"售价:%@"),model.money_name];
  89. }
  90. }
  91. - (void)clickCell
  92. {
  93. if (_delegate && [_delegate respondsToSelector:@selector(clickWithRechargeDesCell:)])
  94. {
  95. [_delegate clickWithRechargeDesCell:self];
  96. }
  97. }
  98. @end