MineServiceView.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // MineServiceView.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/9/5.
  6. //
  7. #import "MineServiceView.h"
  8. @interface MineServiceView ()
  9. @property (nonatomic, copy) MineViewCallback callback;
  10. @property (nonatomic, strong) NSMutableArray *imageArray;
  11. @property (nonatomic, strong) NSMutableArray *titleArray;
  12. @property (nonatomic, strong) NSMutableArray *tagArray;
  13. @property (weak, nonatomic) IBOutlet UIView *containerView;
  14. @end
  15. @implementation MineServiceView
  16. + (instancetype)shareInstance {
  17. MineServiceView *view = [[[NSBundle mainBundle] loadNibNamed:@"MineServiceView" owner:nil options:nil] firstObject];
  18. return view;
  19. }
  20. - (void)configView {
  21. [self.containerView removeAllSubViews];
  22. CGFloat space = (KPortraitWidth - 28 - 4 * FUNCTIONVIEW_WIDTH) / 5.0f;
  23. BOOL tagHandle = NO;
  24. for (NSInteger index = 0; index < self.imageArray.count; index++) {
  25. if (self.isMember == NO && index == 3) {
  26. tagHandle = YES;
  27. continue;
  28. }
  29. MineActionView *functionButton = [MineActionView shareInstance];
  30. NSNumber *tagValue = self.tagArray[index];
  31. MINEVIEWTYPE type = [tagValue intValue];
  32. MJWeakSelf;
  33. [functionButton configWithSource:self.imageArray[index] title:self.titleArray[index] functionType:type callback:^(MINEVIEWTYPE type) {
  34. if (weakSelf.callback) {
  35. weakSelf.callback(type);
  36. }
  37. }];
  38. CGRect frame = CGRectZero;
  39. if (tagHandle) {
  40. frame = CGRectMake(space + (index - 1) % 4 * (space + FUNCTIONVIEW_WIDTH), FUNCTIONVIEW_WIDTH * ((index-1) / 4), FUNCTIONVIEW_WIDTH, FUNCTIONVIEW_HEIGHT);
  41. }
  42. else {
  43. frame = CGRectMake(space + index % 4 * (space + FUNCTIONVIEW_WIDTH), FUNCTIONVIEW_WIDTH * (index / 4), FUNCTIONVIEW_WIDTH, FUNCTIONVIEW_HEIGHT);
  44. }
  45. functionButton.frame = frame;
  46. [self.containerView addSubview:functionButton];
  47. }
  48. }
  49. - (void)functionViewAction:(MineViewCallback)callback {
  50. if (callback) {
  51. self.callback = callback;
  52. }
  53. }
  54. - (CGFloat)getViewHeight {
  55. return 232.0f;
  56. }
  57. - (NSMutableArray *)imageArray {
  58. if (!_imageArray) {
  59. _imageArray = [NSMutableArray arrayWithArray:@[@"tool_myLive",@"tool_liveCourse",@"tool_videoCourse",@"tool_musicRoom",@"tool_myAccompany",@"tool_homework",@"tool_evaluate"]];
  60. }
  61. return _imageArray;
  62. }
  63. - (NSMutableArray *)titleArray {
  64. if (!_titleArray) {
  65. _titleArray = [NSMutableArray arrayWithArray:@[@"商品订单",@"交易记录",@"优惠券"]];
  66. }
  67. return _titleArray;
  68. }
  69. - (NSMutableArray *)tagArray {
  70. if (!_tagArray) {
  71. _tagArray = [NSMutableArray arrayWithArray:@[@(MINEVIEWTYPE_ORDER),@(MINEVIEWTYPE_DEAL),@(MINEVIEWTYPE_TICKET)]];
  72. }
  73. return _tagArray;
  74. }
  75. /*
  76. // Only override drawRect: if you perform custom drawing.
  77. // An empty implementation adversely affects performance during animation.
  78. - (void)drawRect:(CGRect)rect {
  79. // Drawing code
  80. }
  81. */
  82. @end