ASAddGiftGoodsView.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // ASAddGiftGoodsView.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/5/13.
  6. //
  7. #import "ASAddGiftGoodsView.h"
  8. @interface ASAddGiftGoodsView()
  9. @property (nonatomic, strong) UIImageView *goodsImage;
  10. @end
  11. @implementation ASAddGiftGoodsView
  12. - (instancetype)initWithFrame:(CGRect)frame {
  13. if (self = [super initWithFrame:frame]) {
  14. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
  15. UIView *backView = [[UIView alloc] init];
  16. backView.backgroundColor = Col_FFF;
  17. TT_ViewRadius(backView, 8);
  18. [self addSubview:backView];
  19. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  20. make.center.equalTo(self);
  21. make.width.mas_equalTo(300);
  22. }];
  23. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  24. [closeBtn setImage:[UIImage imageNamed:@"base_close_black"] forState:UIControlStateNormal];
  25. [closeBtn addTarget:self action:@selector(_closeClick) forControlEvents:UIControlEventTouchUpInside];
  26. [backView addSubview:closeBtn];
  27. [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.top.mas_equalTo(10);
  29. make.right.mas_equalTo(-10);
  30. make.width.height.mas_equalTo(36);
  31. }];
  32. UILabel *topLab = [UILabel labelCreateWithText:@"Congratulations!" font:[UIFont fontWithName:Rob_Bold size:14] textColor:Col_000];
  33. [backView addSubview:topLab];
  34. [topLab mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.centerX.equalTo(backView);
  36. make.top.mas_equalTo(56);
  37. }];
  38. UILabel *descLab = [UILabel labelCreateWithText:@"You got a free gift" font:[UIFont fontWithName:Rob_Regular size:14] textColor:Col_000];
  39. [backView addSubview:descLab];
  40. [descLab mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.centerX.equalTo(backView);
  42. make.top.mas_equalTo(topLab.mas_bottom).offset(10);
  43. }];
  44. _goodsImage = [[UIImageView alloc] init];
  45. [backView addSubview:_goodsImage];
  46. [_goodsImage mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.centerX.equalTo(backView);
  48. make.top.mas_equalTo(descLab.mas_bottom).offset(10);
  49. make.width.height.mas_equalTo(86);
  50. }];
  51. UIButton *getBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  52. [getBtn setTitle:@"Get" forState:UIControlStateNormal];
  53. [getBtn setTitleColor:Col_FFF forState:UIControlStateNormal];
  54. getBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:14];
  55. getBtn.backgroundColor = Col_000;
  56. [getBtn addTarget:self action:@selector(_addCart) forControlEvents:UIControlEventTouchUpInside];
  57. TT_ViewRadius(getBtn, 4);
  58. [backView addSubview:getBtn];
  59. [getBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(34);
  61. make.right.mas_equalTo(-34);
  62. make.top.equalTo(_goodsImage.mas_bottom).offset(30);
  63. make.height.mas_equalTo(35);
  64. make.bottom.mas_equalTo(-30);
  65. }];
  66. }
  67. return self;
  68. }
  69. - (void)setGiftData:(NSString *)imageStr {
  70. NSString *imageAllStr = [NSString stringWithFormat:@"https:%@%@%@",HostPath,ProductImgPath,imageStr];
  71. [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:imageAllStr] placeholderImage:UIImageDefaultImg_SD];
  72. }
  73. - (void)_addCart {
  74. // [self removeFromSuperview];
  75. if (self.addBlock) {
  76. self.addBlock(1);
  77. }
  78. }
  79. - (void)_closeClick {
  80. if (self.addBlock) {
  81. self.addBlock(1);
  82. }
  83. }
  84. @end