ASProductListMenuHeaderView.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // ASProductListMenuHeaderView.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/12.
  6. //
  7. #import "ASProductListMenuHeaderView.h"
  8. @interface ASProductListMenuHeaderView ()
  9. @property (nonatomic, strong) UIView *sortMenuV;
  10. @property (nonatomic, strong) UIButton *menuBt;
  11. @property (nonatomic, copy) btnClickBlock menuBlock;
  12. @property (nonatomic, copy) btnClickBlock sortBlock;
  13. @end
  14. @implementation ASProductListMenuHeaderView
  15. - (void)setData:(NSString *)sortTitle sortBlock:(btnClickBlock)sortBlock menuBlock:(btnClickBlock)menuBlock {
  16. [self.sortBt setTitle:sortTitle forState:UIControlStateNormal];
  17. self.sortBlock = sortBlock;
  18. self.menuBlock = menuBlock;
  19. }
  20. - (void)sortBtAction {
  21. if (self.sortBlock) {
  22. self.sortBlock();
  23. }
  24. }
  25. - (void)menuBtAction {
  26. if (self.menuBlock) {
  27. self.menuBlock();
  28. }
  29. }
  30. // MARK: - init
  31. - (instancetype)initWithFrame:(CGRect)frame
  32. {
  33. self = [super initWithFrame:frame];
  34. if (self) {
  35. [self loadV];
  36. }
  37. return self;
  38. }
  39. - (void)loadV {
  40. self.sortMenuV.frame = CGRectMake(0, 0, KScreenWidth, 60);
  41. [self.sortBt mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.leading.equalTo(self.sortMenuV).offset(15);
  43. make.height.equalTo(@22);
  44. make.centerY.equalTo(self.sortMenuV);
  45. }];
  46. [self.menuBt mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.trailing.equalTo(self.sortMenuV).offset(-15);
  48. make.width.height.equalTo(@34);
  49. make.centerY.equalTo(self.sortMenuV);
  50. make.leading.greaterThanOrEqualTo(self.sortBt.mas_trailing).offset(10);
  51. }];
  52. [self addSubview:self.sortMenuV];
  53. [self.sortMenuV mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.edges.equalTo(self);
  55. make.height.equalTo(@60);
  56. }];
  57. }
  58. - (UIView *)sortMenuV {
  59. if (!_sortMenuV) {
  60. UIView *v = [UIView baseV];
  61. v.backgroundColor = _F5F5F5;
  62. UIButton *sortBt = [UIButton buttonWithType:UIButtonTypeCustom];
  63. [sortBt setTitle:@"SORT BY" forState:UIControlStateNormal];
  64. [sortBt setTitleColor:Col_000 forState:UIControlStateNormal];
  65. sortBt.titleLabel.font = [UIFont fontWithName:Rob_Bold size:14];
  66. [sortBt addTarget:self action:@selector(sortBtAction) forControlEvents:UIControlEventTouchUpInside];
  67. self.sortBt = sortBt;
  68. UIButton *nBt = [UIButton buttonWithType:UIButtonTypeCustom];
  69. [nBt setImage:[UIImage imageNamed:@"productList_menu"] forState:UIControlStateNormal];
  70. [nBt addTarget:self action:@selector(menuBtAction) forControlEvents:UIControlEventTouchUpInside];
  71. self.menuBt = nBt;
  72. [v addSubview:self.sortBt];
  73. [v addSubview:self.menuBt];
  74. _sortMenuV = v;
  75. }
  76. return _sortMenuV;
  77. }
  78. @end