PKBattleListCell.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // PKBattleListCell.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/3/31.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "PKBattleListCell.h"
  9. @implementation PKBattleListCell
  10. - (void)awakeFromNib {
  11. [super awakeFromNib];
  12. // Initialization code
  13. self.leftImgView.contentMode = UIViewContentModeScaleAspectFill;
  14. self.leftImgView.clipsToBounds = YES;
  15. self.rightImgView.contentMode = UIViewContentModeScaleAspectFill;
  16. self.leftImgView.clipsToBounds = YES;
  17. self.pkLineView.layer.cornerRadius = self.pkLineHeightConstraint.constant / 2;
  18. self.pkLineView.layer.masksToBounds = YES;
  19. self.leftImgView.layer.cornerRadius = 4;
  20. self.leftImgView.layer.masksToBounds = YES;
  21. self.rightImgView.layer.cornerRadius = 4;
  22. self.rightImgView.layer.masksToBounds = YES;
  23. self.leftAddressBtn.spacingBetweenImageAndTitle = 3;
  24. self.leftAddressBtn.imagePosition = QMUIButtonImagePositionLeft;
  25. self.rightAddressBtn.spacingBetweenImageAndTitle = 3;
  26. self.rightAddressBtn.imagePosition = QMUIButtonImagePositionLeft;
  27. self.leftImgView.userInteractionEnabled = YES;
  28. self.rightImgView.userInteractionEnabled = YES;
  29. UITapGestureRecognizer *tapLeft = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickLeftTap:)];
  30. [self.leftImgView addGestureRecognizer:tapLeft];
  31. UITapGestureRecognizer *tapRight = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickRightTap:)];
  32. [self.rightImgView addGestureRecognizer:tapRight];
  33. }
  34. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  35. [super setSelected:selected animated:animated];
  36. // Configure the view for the selected state
  37. }
  38. -(void)clickLeftTap:(UITapGestureRecognizer *)sender{
  39. if (self.delegate && [self.delegate respondsToSelector:@selector(clickBattleModel:LeftOrRight:)]) {
  40. [self.delegate clickBattleModel:self.model LeftOrRight:YES];
  41. }
  42. }
  43. -(void)clickRightTap:(UITapGestureRecognizer *)sender{
  44. if (self.delegate && [self.delegate respondsToSelector:@selector(clickBattleModel:LeftOrRight:)]) {
  45. [self.delegate clickBattleModel:self.model LeftOrRight:NO];
  46. }
  47. }
  48. - (void)setModel:(PKBattleListModel *)model{
  49. _model = model;
  50. self.leftNameL.text = model.name1;
  51. if (StrValid(model.city1)) {
  52. [self.leftAddressBtn setImage:[UIImage imageNamed:@"bogo_pk_battle_address"] forState:UIControlStateNormal];
  53. [self.leftAddressBtn setTitle:model.city1 forState:UIControlStateNormal];
  54. }
  55. if (StrValid(model.city1)) {
  56. [self.rightAddressBtn setImage:[UIImage imageNamed:@"bogo_pk_battle_address"] forState:UIControlStateNormal];
  57. [self.rightAddressBtn setTitle:model.city2 forState:UIControlStateNormal];
  58. }
  59. if (StrValid(model.live_image1)) {
  60. [self.leftImgView sd_setImageWithURL:[NSURL URLWithString:model.live_image1] completed:nil];
  61. }else{
  62. [self.leftImgView sd_setImageWithURL:[NSURL URLWithString:model.head_image1] completed:nil];
  63. }
  64. if (StrValid(model.live_image2)) {
  65. [self.rightImgView sd_setImageWithURL:[NSURL URLWithString:model.live_image2] completed:nil];
  66. }else{
  67. [self.rightImgView sd_setImageWithURL:[NSURL URLWithString:model.head_image2] completed:nil];
  68. }
  69. self.rightNameL.text = model.name2;
  70. if (model.pk_ticket1.intValue == model.pk_ticket2.intValue) {
  71. self.leftWidthConstraint.constant = (kScreenW - 12 * 2) / 2;
  72. self.rightWidthConstraint.constant = (kScreenW - 12 * 2) / 2;
  73. // self.leftPKWidth.constant = 0.5;
  74. // self.rightPKWidth.constant = 0.5;
  75. // [self.leftPKView mas_updateConstraints:^(MASConstraintMaker *make) {
  76. // make.width.mas_equalTo(kScreenW * 0.5);
  77. // }];
  78. // [self.leftPKView mas_updateConstraints:^(MASConstraintMaker *make) {
  79. // make.width.mas_equalTo(kScreenW * 0.5);
  80. // }];
  81. }else{
  82. // self.leftPKWidth.multiplier = 0.7;
  83. // model.pk_ticket1.floatValue / (model.pk_ticket1.floatValue + model.pk_ticket2.floatValue) ;
  84. // self.rightPKWidth.constant = 0.3;
  85. //// model.pk_ticket2.floatValue / (model.pk_ticket1.floatValue + model.pk_ticket2.floatValue) ;
  86. //
  87. // [self.leftPKView mas_updateConstraints:^(MASConstraintMaker *make) {
  88. // make.width.mas_equalTo(kScreenW * 0.2);
  89. // }];
  90. // [self.leftPKView mas_updateConstraints:^(MASConstraintMaker *make) {
  91. // make.width.mas_equalTo(kScreenW * 0.7);
  92. // }];
  93. CGFloat leftWidthScale = model.pk_ticket1.floatValue / (model.pk_ticket1.floatValue + model.pk_ticket2.floatValue);
  94. CGFloat rightWidthScale = model.pk_ticket2.floatValue / (model.pk_ticket1.floatValue + model.pk_ticket2.floatValue);
  95. self.leftWidthConstraint.constant = (kScreenW - 12 * 2) * leftWidthScale;
  96. self.rightWidthConstraint.constant = (kScreenW - 12 * 2) * rightWidthScale;
  97. }
  98. self.leftTicketL.text = [NSString stringWithFormat:@"%@",model.pk_ticket1];
  99. self.rightTicketL.text = [NSString stringWithFormat:@"%@",model.pk_ticket2];
  100. // [self.rightPKView mas_updateConstraints:^(MASConstraintMaker *make) {
  101. // make.right.mas_equalTo(self.leftPKView.mas_right).offset(-20);
  102. // make.width.mas_equalTo(kScreenW * 0.2);
  103. // }];
  104. // [self.leftPKView mas_remakeConstraints:^(MASConstraintMaker *make) {
  105. // make.width.mas_equalTo(kScreenW * 0.2);
  106. // }];
  107. //
  108. // [self.rightPKView mas_remakeConstraints:^(MASConstraintMaker *make) {
  109. // make.width.mas_equalTo(kScreenW * 0.7);
  110. // }];
  111. [self setLeftPKView:self.leftPKView];
  112. [self setRightPKView:self.rightPKView];
  113. }
  114. - (void)setLeftPKView:(UIView *)leftPKView{
  115. // CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  116. // gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:@"#0A86EB"].CGColor, (__bridge id)[UIColor colorWithHexString:@"#3BA7EF"].CGColor];
  117. // gradientLayer.locations = @[@0.3, @0.5, @1.0];
  118. // gradientLayer.startPoint = CGPointMake(0, 0);
  119. // gradientLayer.endPoint = CGPointMake(1.0, 0);
  120. // gradientLayer.frame = leftPKView.bounds;
  121. // [leftPKView.layer addSublayer:gradientLayer];
  122. }
  123. - (void)setRightPKView:(UIView *)rightPKView{
  124. // CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  125. // gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:@"#FF72AF"].CGColor, (__bridge id)[UIColor colorWithHexString:@"#F61275"].CGColor];
  126. // gradientLayer.locations = @[@0.3, @0.5, @1.0];
  127. // gradientLayer.startPoint = CGPointMake(0, 0);
  128. // gradientLayer.endPoint = CGPointMake(1.0, 0);
  129. // gradientLayer.frame = rightPKView.bounds;
  130. // [rightPKView.layer addSublayer:gradientLayer];
  131. }
  132. - (void)layoutSubviews {
  133. [super layoutSubviews];
  134. }
  135. @end