AuctionPayView.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // AuctionPayView.m
  3. // BuguLive
  4. //
  5. // Created by 王珂 on 16/10/26.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "AuctionPayView.h"
  9. @interface AuctionPayView()
  10. @property (nonatomic, strong) UIImageView * auctionGoodsView; //商品图片
  11. @property (nonatomic, strong) UILabel * titleLabel; //商品介绍
  12. @property (nonatomic, strong) UIImageView * diamondView; //钻石图片
  13. @property (nonatomic, strong) UILabel * priceLabel; //商品价格
  14. @property (nonatomic, strong) UIView * rechargeContainerView;
  15. @property (nonatomic, strong) UILabel * txtLabel; //充值
  16. @property (nonatomic, strong) UILabel *diamondsLabel; //账户剩余钻石
  17. @property (nonatomic, strong) UIImageView *diamondsImgView; //钻石图标
  18. @property (nonatomic, strong) UIImageView *diamondsArrowImgView; //右箭头
  19. @property (nonatomic, strong) UIButton * cancelBtn;
  20. @property (nonatomic, strong) UIButton * payBtn;
  21. @property (nonatomic, strong) UIButton * chargeBtn;
  22. @end
  23. @implementation AuctionPayView
  24. - (instancetype)initWithFrame:(CGRect)frame
  25. {
  26. if (self = [super initWithFrame:frame])
  27. {
  28. _auctionGoodsView =[[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 90, 70)];
  29. [self addSubview:_auctionGoodsView];
  30. _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_auctionGoodsView.frame)+5, 5, kScreenW-CGRectGetMaxX(_auctionGoodsView.frame)-10, 40)];
  31. //titleLabel.text = ASLocalizedString(@"商品介绍");
  32. _titleLabel.numberOfLines = 0;
  33. _titleLabel.font = kAppMiddleTextFont;
  34. _titleLabel.textColor = kAppGrayColor1;
  35. [self addSubview:_titleLabel];
  36. _diamondView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_auctionGoodsView.frame)+5, CGRectGetMaxY(_titleLabel.frame)+7, 20, 15)];
  37. _diamondView.image = [UIImage imageNamed:@"com_diamond_1"];
  38. [self addSubview:_diamondView];
  39. _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_diamondView.frame)+5, CGRectGetMaxY(_titleLabel.frame)+5, kScreenW-145-CGRectGetMaxX(_diamondView.frame), 20)];
  40. //priceLabel.text =ASLocalizedString(@"付款价格");
  41. _priceLabel.textColor = kAppGrayColor1;
  42. _priceLabel.font = kAppSmallTextFont;
  43. [self addSubview:_priceLabel];
  44. _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenW-135, CGRectGetMaxY(_titleLabel.frame)+5,135 ,20)];
  45. // _timeLabel.text = [NSString stringWithFormat:ASLocalizedString(@"剩%02d分%02d秒 自动关闭"),_payMinute,_paySecond];
  46. _timeLabel.textColor = kAppGrayColor1;
  47. _timeLabel.font = kAppSmallTextFont;
  48. [self addSubview:_timeLabel];
  49. _rechargeContainerView = [[UIView alloc]initWithFrame:CGRectMake(0, 90, 170, 40)];
  50. [self addSubview:_rechargeContainerView];
  51. _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  52. _cancelBtn.backgroundColor = kAppMainColor;
  53. _cancelBtn.frame = CGRectMake(kScreenW-140, 95, 60, 30);
  54. _cancelBtn.titleLabel.font = kAppSmallTextFont;
  55. [_cancelBtn setTitle:ASLocalizedString(@"取消")forState:UIControlStateNormal];
  56. _cancelBtn.layer.cornerRadius = 15;
  57. _cancelBtn.layer.masksToBounds = YES;
  58. [_cancelBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  59. [self addSubview:_cancelBtn];
  60. _payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  61. _payBtn.backgroundColor = kAppMainColor;
  62. _payBtn.frame = CGRectMake(kScreenW-70, 95, 60, 30);
  63. _payBtn.titleLabel.font = kAppSmallTextFont;
  64. [_payBtn setTitle:ASLocalizedString(@"付款")forState:UIControlStateNormal];
  65. _payBtn.layer.cornerRadius = 15;
  66. _payBtn.layer.masksToBounds = YES;
  67. [_payBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  68. [self addSubview:_payBtn];
  69. }
  70. return self;
  71. }
  72. - (void)creatWith:(UserModel *)model withCurrentDiamonds:(NSInteger )currentDiamonds withPrice:(NSString *)priceStr
  73. {
  74. _titleLabel.text = model.goods_name;
  75. _priceLabel.text = priceStr;
  76. [_auctionGoodsView sd_setImageWithURL:[NSURL URLWithString:model.goods_icon]];
  77. UILabel *txtLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 30, CGRectGetHeight(_rechargeContainerView.frame))];
  78. txtLabel.font = kAppSmallTextFont;
  79. txtLabel.textAlignment = NSTextAlignmentCenter;
  80. txtLabel.text = ASLocalizedString(@"充值");
  81. [_rechargeContainerView addSubview:txtLabel];
  82. NSString * str = [NSString stringWithFormat:@"%ld",(long)currentDiamonds];
  83. CGSize titleSize = [str boundingRectWithSize:CGSizeMake(100, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:kAppSmallTextFont} context:nil].size;
  84. _diamondsLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(txtLabel.frame), 0, titleSize.width, CGRectGetHeight(_rechargeContainerView.frame))];
  85. _diamondsLabel.font = kAppSmallTextFont;
  86. _diamondsLabel.text = str;
  87. [_rechargeContainerView addSubview:_diamondsLabel];
  88. _diamondsImgView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_diamondsLabel.frame)+3,(CGRectGetHeight(_rechargeContainerView.frame)-15)/2, 20, 15)];
  89. _diamondsImgView.contentMode = UIViewContentModeScaleAspectFit;
  90. [_diamondsImgView setImage:[UIImage imageNamed:@"com_diamond_1"]];
  91. [_rechargeContainerView addSubview:_diamondsImgView];
  92. _diamondsArrowImgView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_diamondsImgView.frame)+3,(CGRectGetHeight(_rechargeContainerView.frame)-12)/2, 6, 12)];
  93. _diamondsArrowImgView.contentMode = UIViewContentModeScaleAspectFit;
  94. [_diamondsArrowImgView setImage:[UIImage imageNamed:@"com_arrow_right_1"]];
  95. [_rechargeContainerView addSubview:_diamondsArrowImgView];
  96. _chargeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 150, 40)];
  97. _chargeBtn.width = CGRectGetMaxX(_diamondsArrowImgView.frame);
  98. [_rechargeContainerView addSubview:_chargeBtn];
  99. [_chargeBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  100. }
  101. - (void)setDiamondsText:(NSString *)txt
  102. {
  103. _diamondsLabel.text = txt;
  104. CGSize titleSize = [txt boundingRectWithSize:CGSizeMake(100, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:kAppSmallTextFont} context:nil].size;
  105. _diamondsLabel.frame = CGRectMake(_diamondsLabel.frame.origin.x, _diamondsLabel.frame.origin.y, titleSize.width, _diamondsLabel.frame.size.height);
  106. _diamondsImgView.frame = CGRectMake(CGRectGetMaxX(_diamondsLabel.frame)+3,_diamondsImgView.frame.origin.y, _diamondsImgView.frame.size.width, _diamondsImgView.frame.size.height);
  107. _diamondsArrowImgView.frame = CGRectMake(CGRectGetMaxX(_diamondsImgView.frame)+3,_diamondsArrowImgView.frame.origin.y, _diamondsArrowImgView.frame.size.width, _diamondsArrowImgView.frame.size.height);
  108. _chargeBtn.width = CGRectGetMaxX(_diamondsArrowImgView.frame);
  109. }
  110. - (void)clickBtn:(UIButton *)button
  111. {
  112. if (button==_cancelBtn)
  113. {
  114. if (_delegate && [_delegate respondsToSelector:@selector(cancelPay)])
  115. {
  116. [_delegate cancelPay];
  117. }
  118. }
  119. else if (button==_payBtn)
  120. {
  121. if (_delegate && [_delegate respondsToSelector:@selector(clickToPay)])
  122. {
  123. [_delegate clickToPay];
  124. }
  125. }
  126. else if (button==_chargeBtn)
  127. {
  128. if (_delegate && [_delegate respondsToSelector:@selector(clickRechargeAction)])
  129. {
  130. [_delegate clickRechargeAction];
  131. }
  132. }
  133. }
  134. @end