ShopGoodsView.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // ShopGoodsView.m
  3. // BuguLive
  4. //
  5. // Created by 王珂 on 16/10/31.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "ShopGoodsView.h"
  9. @interface ShopGoodsView()
  10. @property (nonatomic, strong) UIImageView * goodsImage;//商品图片
  11. @property (nonatomic, strong) UIImageView * arrowImage;//箭头
  12. @property (nonatomic, strong) UIImageView * diamondsView; //钻石图片
  13. @property (nonatomic, strong) UILabel * titleLabel; //商品名称
  14. @property (nonatomic, strong) UILabel * priceLabel; //价格
  15. @property (nonatomic, strong) UIButton * goodsBtn;//按钮
  16. @property (nonatomic, strong) UIButton * sendAnchorBtn;//送给主播
  17. @property (nonatomic, strong) UIButton * giveSelfBtn;//买给自己
  18. @end
  19. @implementation ShopGoodsView
  20. - (instancetype)initWithFrame:(CGRect)frame
  21. {
  22. if (self = [super initWithFrame:frame])
  23. {
  24. _goodsImage = [[UIImageView alloc] init];
  25. _goodsImage.contentMode = UIViewContentModeScaleAspectFill;
  26. _goodsImage.clipsToBounds = YES;
  27. [self addSubview:_goodsImage];
  28. _titleLabel = [[UILabel alloc] init];
  29. _titleLabel.font = kAppMiddleTextFont;
  30. _titleLabel.textColor = kAppGrayColor1;
  31. _titleLabel.numberOfLines = 0;
  32. [self addSubview:_titleLabel];
  33. _diamondsView = [[UIImageView alloc] init];
  34. _diamondsView.image = [UIImage imageNamed:@"com_diamond_1"];
  35. [self addSubview:_diamondsView];
  36. _priceLabel = [[UILabel alloc] init];
  37. _priceLabel.font = kAppSmallTextFont;
  38. _priceLabel.textColor = kAppGrayColor1;
  39. [self addSubview:_priceLabel];
  40. _sendAnchorBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  41. _sendAnchorBtn.backgroundColor = [UIColor flatYellowColor];
  42. _sendAnchorBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  43. [self addSubview:_sendAnchorBtn];
  44. _giveSelfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  45. _giveSelfBtn.backgroundColor = kAppMainColor;
  46. _giveSelfBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  47. [self addSubview:_giveSelfBtn];
  48. _goodsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  49. [_goodsBtn addTarget:self action:@selector(clickGoodsBtn) forControlEvents:UIControlEventTouchUpInside];
  50. [self addSubview:_goodsBtn];
  51. }
  52. return self;
  53. }
  54. - (void)setModel:(GoodsModel *)model
  55. {
  56. _model = model;
  57. _goodsImage.frame = CGRectMake(5, 5, 90, 90);
  58. _goodsBtn.frame = CGRectMake(0, 0, 300, 100);
  59. if (model.url.length>0 && model.type == 1)
  60. {
  61. _titleLabel.frame = CGRectMake(CGRectGetMaxX(_goodsImage.frame)+3, 10, 195, 55);
  62. _priceLabel.frame = CGRectMake(CGRectGetMaxX(_goodsImage.frame)+3, CGRectGetMaxY(_titleLabel.frame)+10, 180, 15);
  63. }
  64. else
  65. {
  66. if (_type==0)
  67. {
  68. _sendAnchorBtn.hidden = YES;
  69. _giveSelfBtn.hidden = YES;
  70. _sendAnchorBtn.enabled = NO;
  71. _giveSelfBtn.enabled = NO;
  72. _titleLabel.frame = CGRectMake(CGRectGetMaxX(_goodsImage.frame)+3, 15, 195, 40);
  73. _priceLabel.frame = CGRectMake(CGRectGetMaxX(_goodsImage.frame)+3, CGRectGetMaxY(_titleLabel.frame)+15, 180, 15);
  74. }
  75. else if (_type==1)
  76. {
  77. _sendAnchorBtn.hidden = kSupportH5Shopping ? YES : NO;
  78. _giveSelfBtn.hidden = kSupportH5Shopping ? YES : NO;
  79. _sendAnchorBtn.enabled = kSupportH5Shopping ? NO : YES;
  80. _giveSelfBtn.enabled = kSupportH5Shopping ? NO : YES;
  81. _titleLabel.frame = CGRectMake(CGRectGetMaxX(_goodsImage.frame)+3, 5, 195, 40);
  82. _priceLabel.frame = CGRectMake(CGRectGetMaxX(_goodsImage.frame)+3, CGRectGetMaxY(_titleLabel.frame)+5, 180, 15);
  83. _sendAnchorBtn.frame = CGRectMake(155, CGRectGetMaxY(_priceLabel.frame)+5, 55, 25);
  84. _giveSelfBtn.frame = CGRectMake(CGRectGetMaxX(_sendAnchorBtn.frame)+20, CGRectGetMaxY(_priceLabel.frame)+5, 55, 25);
  85. _sendAnchorBtn.layer.cornerRadius = 5;
  86. _sendAnchorBtn.layer.masksToBounds = YES;
  87. _giveSelfBtn.layer.cornerRadius = 5;
  88. _giveSelfBtn.layer.masksToBounds = YES;
  89. [_sendAnchorBtn setTitle:ASLocalizedString(@"送给主播")forState:UIControlStateNormal];
  90. [_giveSelfBtn setTitle:ASLocalizedString(@"买给自己")forState:UIControlStateNormal];
  91. [_sendAnchorBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  92. [_giveSelfBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  93. }
  94. }
  95. [_goodsImage sd_setImageWithURL:[NSURL URLWithString:model.imgs] placeholderImage:[UIImage imageNamed:@"DefaultImg"]];
  96. _titleLabel.text = model.name;
  97. _priceLabel.text = [NSString stringWithFormat:@"¥ %@",model.price];
  98. }
  99. - (void)clickGoodsBtn
  100. {
  101. if (_delegate && [_delegate respondsToSelector:@selector(toGoods)])
  102. {
  103. [_delegate toGoods];
  104. }
  105. }
  106. - (void)clickBtn:(UIButton *) button
  107. {
  108. if (button==_sendAnchorBtn)
  109. {
  110. if (_delegate && [_delegate respondsToSelector:@selector(toGoods)])
  111. {
  112. [_delegate toGoods];
  113. }
  114. }
  115. else if (button==_giveSelfBtn)
  116. {
  117. if (_delegate && [_delegate respondsToSelector:@selector(toGoods)]) {
  118. [_delegate toGoods];
  119. }
  120. }
  121. }
  122. @end