ASUserCenterEnterItemV.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // ASUserCenterEnterItemV.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/5/16.
  6. //
  7. #import "ASUserCenterEnterItemV.h"
  8. #import "ASEnterItemV.h"
  9. @interface ASUserCenterEnterItemV ()
  10. @property (nonatomic, strong) UIView *bgV;
  11. @property (nonatomic, strong) UIStackView *enterStackV;
  12. @property (nonatomic, strong) UIStackView *enterStackV2;
  13. @property (nonatomic, strong) NSArray<ASEnterItemV *> *itemsV;
  14. @end
  15. @implementation ASUserCenterEnterItemV
  16. - (instancetype)initWithFrame:(CGRect)frame {
  17. CGRect rect = frame;
  18. rect.size = CGSizeMake(KScreenWidth, 219);
  19. self = [super initWithFrame:rect];
  20. if (self) {
  21. [self createItemsV];
  22. [self configSubV];
  23. }
  24. return self;
  25. }
  26. - (void)configSubV {
  27. [self addSubview:self.bgV];
  28. [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.leading.top.equalTo(self).offset(10);
  30. make.bottom.trailing.equalTo(self).offset(-10);
  31. }];
  32. UIStackView *totalSt = [UIStackView baseStackV:true];
  33. totalSt.distribution = UIStackViewDistributionFillEqually;
  34. totalSt.spacing = 10;
  35. [totalSt addArrangedSubview:self.enterStackV];
  36. [totalSt addArrangedSubview:self.enterStackV2];
  37. [self.bgV addSubview:totalSt];
  38. [totalSt mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.leading.equalTo(self).offset(15);
  40. make.trailing.equalTo(self).offset(-15);
  41. make.top.equalTo(self).offset(30);
  42. make.bottom.equalTo(self).offset(-30);
  43. }];
  44. for (int i=0; i<self.itemsV.count;i++) {
  45. int a = i/3;
  46. ASEnterItemV *v = self.itemsV[i];
  47. if (a == 0) {
  48. [self.enterStackV addArrangedSubview:v];
  49. } else {
  50. [self.enterStackV2 addArrangedSubview:v];
  51. }
  52. }
  53. }
  54. - (UIView *)bgV {
  55. if (!_bgV) {
  56. UIView *v = [UIView baseV];
  57. v.layer.cornerRadius = 8;
  58. v.layer.masksToBounds = true;
  59. v.backgroundColor = _F8F8F8;
  60. _bgV = v;
  61. }
  62. return _bgV;
  63. }
  64. - (UIStackView *)enterStackV {
  65. if (!_enterStackV) {
  66. UIStackView *v = [[UIStackView alloc] init];
  67. v.axis = UILayoutConstraintAxisHorizontal;
  68. v.spacing = 10;
  69. v.alignment = UIStackViewAlignmentFill;
  70. v.distribution = UIStackViewDistributionFillEqually;
  71. _enterStackV = v;
  72. }
  73. return _enterStackV;
  74. }
  75. - (UIStackView *)enterStackV2 {
  76. if (!_enterStackV2) {
  77. UIStackView *v = [[UIStackView alloc] init];
  78. v.axis = UILayoutConstraintAxisHorizontal;
  79. v.spacing = 10;
  80. v.alignment = UIStackViewAlignmentFill;
  81. v.distribution = UIStackViewDistributionFillEqually;
  82. _enterStackV2 = v;
  83. }
  84. return _enterStackV2;
  85. }
  86. - (void)createItemsV {
  87. NSArray *titleArr = @[@"Coupons", @"Gift Card", @"Points" , @"VIP Center",@"Customer Service",@"Message"];
  88. NSArray *iconArr = @[@"uc_coupons", @"uc_giftcard",@"uc_points", @"uc_VIPCenter",@"uc_service",@"uc_message"];
  89. NSMutableArray *tempArr = [NSMutableArray array];
  90. for (int i = 0; i<titleArr.count; i++) {
  91. NSString *tit = titleArr[i];
  92. UIImage *img = [UIImage imageNamed:iconArr[i]];
  93. ASEnterItemV *v = [[ASEnterItemV alloc] initWithFrame:CGRectZero];
  94. [v setData:tit icon:img];
  95. @weakify(self);
  96. [v setClickCallBack:^{
  97. [weak_self tapItemAction:i];
  98. }];
  99. [tempArr addObject:v];
  100. }
  101. self.itemsV = tempArr;
  102. }
  103. - (void)tapItemAction:(NSInteger)tag {
  104. if (self.itemTapCallBack) {
  105. self.itemTapCallBack(tag);
  106. }
  107. }
  108. @end