ASProductListMenuHeaderView.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 isSearch:(BOOL)isSearch sortBlock:(btnClickBlock)sortBlock menuBlock:(btnClickBlock)menuBlock {
  16. [self.sortBt setTitle:sortTitle forState:UIControlStateNormal];
  17. self.menuBt.hidden = isSearch;
  18. self.sortBlock = sortBlock;
  19. self.menuBlock = menuBlock;
  20. }
  21. - (void)sortBtAction {
  22. if (self.sortBlock) {
  23. self.sortBlock();
  24. }
  25. }
  26. - (void)menuBtAction {
  27. if (self.menuBlock) {
  28. self.menuBlock();
  29. }
  30. }
  31. // MARK: - init
  32. - (instancetype)initWithFrame:(CGRect)frame
  33. {
  34. self = [super initWithFrame:frame];
  35. if (self) {
  36. [self loadV];
  37. }
  38. return self;
  39. }
  40. - (void)loadV {
  41. self.sortMenuV.frame = CGRectMake(0, 0, KScreenWidth, 60);
  42. [self.sortBt mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.leading.equalTo(self.sortMenuV).offset(15);
  44. make.height.equalTo(@22);
  45. make.centerY.equalTo(self.sortMenuV);
  46. }];
  47. [self.menuBt mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.trailing.equalTo(self.sortMenuV).offset(-15);
  49. make.width.height.equalTo(@34);
  50. make.centerY.equalTo(self.sortMenuV);
  51. make.leading.greaterThanOrEqualTo(self.sortBt.mas_trailing).offset(10);
  52. }];
  53. [self addSubview:self.sortMenuV];
  54. [self.sortMenuV mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.edges.equalTo(self);
  56. make.height.equalTo(@60);
  57. }];
  58. }
  59. - (UIView *)sortMenuV {
  60. if (!_sortMenuV) {
  61. UIView *v = [UIView baseV];
  62. v.backgroundColor = _F5F5F5;
  63. UIButton *sortBt = [UIButton buttonWithType:UIButtonTypeCustom];
  64. [sortBt setTitle:@"SORT BY" forState:UIControlStateNormal];
  65. [sortBt setTitleColor:Col_000 forState:UIControlStateNormal];
  66. sortBt.titleLabel.font = [UIFont fontWithName:Rob_Bold size:14];
  67. [sortBt addTarget:self action:@selector(sortBtAction) forControlEvents:UIControlEventTouchUpInside];
  68. self.sortBt = sortBt;
  69. UIButton *nBt = [UIButton buttonWithType:UIButtonTypeCustom];
  70. [nBt setImage:[UIImage imageNamed:@"productList_menu"] forState:UIControlStateNormal];
  71. [nBt addTarget:self action:@selector(menuBtAction) forControlEvents:UIControlEventTouchUpInside];
  72. self.menuBt = nBt;
  73. [v addSubview:self.sortBt];
  74. [v addSubview:self.menuBt];
  75. _sortMenuV = v;
  76. }
  77. return _sortMenuV;
  78. }
  79. @end