ASUserCenterEnterItemV.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.backgroundColor = Col_FFF;
  28. [self addSubview:self.bgV];
  29. [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.leading.top.equalTo(self).offset(10);
  31. make.bottom.trailing.equalTo(self).offset(-10);
  32. }];
  33. UIStackView *totalSt = [UIStackView baseStackV:true];
  34. totalSt.distribution = UIStackViewDistributionFillEqually;
  35. totalSt.spacing = 10;
  36. [totalSt addArrangedSubview:self.enterStackV];
  37. [totalSt addArrangedSubview:self.enterStackV2];
  38. [self.bgV addSubview:totalSt];
  39. [totalSt mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.leading.equalTo(self).offset(15);
  41. make.trailing.equalTo(self).offset(-15);
  42. make.top.equalTo(self).offset(30);
  43. make.bottom.equalTo(self).offset(-30);
  44. }];
  45. for (int i=0; i<self.itemsV.count;i++) {
  46. int a = i/3;
  47. ASEnterItemV *v = self.itemsV[i];
  48. if (a == 0) {
  49. [self.enterStackV addArrangedSubview:v];
  50. } else {
  51. [self.enterStackV2 addArrangedSubview:v];
  52. }
  53. }
  54. }
  55. - (UIView *)bgV {
  56. if (!_bgV) {
  57. UIView *v = [UIView baseV];
  58. v.layer.cornerRadius = 8;
  59. v.layer.masksToBounds = true;
  60. v.backgroundColor = _F8F8F8;
  61. _bgV = v;
  62. }
  63. return _bgV;
  64. }
  65. - (UIStackView *)enterStackV {
  66. if (!_enterStackV) {
  67. UIStackView *v = [[UIStackView alloc] init];
  68. v.axis = UILayoutConstraintAxisHorizontal;
  69. v.spacing = 10;
  70. v.alignment = UIStackViewAlignmentFill;
  71. v.distribution = UIStackViewDistributionFillEqually;
  72. _enterStackV = v;
  73. }
  74. return _enterStackV;
  75. }
  76. - (UIStackView *)enterStackV2 {
  77. if (!_enterStackV2) {
  78. UIStackView *v = [[UIStackView alloc] init];
  79. v.axis = UILayoutConstraintAxisHorizontal;
  80. v.spacing = 10;
  81. v.alignment = UIStackViewAlignmentFill;
  82. v.distribution = UIStackViewDistributionFillEqually;
  83. _enterStackV2 = v;
  84. }
  85. return _enterStackV2;
  86. }
  87. - (void)createItemsV {
  88. NSArray *titleArr = @[@"Coupons", @"Gift Card", @"Points" , @"VIP Center",@"Customer Service",@"Message"];
  89. NSArray *iconArr = @[@"uc_coupons", @"uc_giftcard",@"uc_points", @"uc_VIPCenter",@"uc_service",@"uc_message"];
  90. NSMutableArray *tempArr = [NSMutableArray array];
  91. for (int i = 0; i<titleArr.count; i++) {
  92. NSString *tit = titleArr[i];
  93. UIImage *img = [UIImage imageNamed:iconArr[i]];
  94. ASEnterItemV *v = [[ASEnterItemV alloc] initWithFrame:CGRectZero];
  95. [v setData:tit icon:img];
  96. @weakify(self);
  97. [v setClickCallBack:^{
  98. [weak_self tapItemAction:i];
  99. }];
  100. [tempArr addObject:v];
  101. }
  102. self.itemsV = tempArr;
  103. }
  104. - (void)tapItemAction:(NSInteger)tag {
  105. if (self.itemTapCallBack) {
  106. self.itemTapCallBack(tag);
  107. }
  108. }
  109. @end