CloudStorageBar.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // CloudStorageBar.m
  3. // zhuxun
  4. //
  5. // Created by winsoft on 17/6/20.
  6. //
  7. //
  8. #import "CloudStorageBar.h"
  9. #import "CustomSearchBar.h"
  10. #import "CustomButton.h"
  11. #import <FTPopOverMenu/FTPopOverMenu.h>
  12. #define MarginX 20
  13. #define BtnWH 22
  14. @interface CloudStorageBar()<UISearchBarDelegate>
  15. @property (nonatomic, weak)CustomButton *folderCreateBtn;
  16. @property (nonatomic, weak)CustomButton *fileSortBtn;
  17. @property (nonatomic, weak)CustomSearchBar *searchBar;
  18. //@property (nonatomic, weak)UISegmentedControl *segmentControl;
  19. @end
  20. @implementation CloudStorageBar
  21. - (instancetype)init
  22. {
  23. if(self = [super init])
  24. {
  25. CustomButton *folderCreateBtn = [[CustomButton alloc]initCustomBtnWithImageDirection:ImagePostionTop imageViewSize:CGSizeMake(BtnWH, BtnWH) imageLabelMargin:0 titleLabelFont:nil imageIcon:@"file_newfolder_n" selectIcon:@"file_newfolder_p" title:nil btnWidth:BtnWH];
  26. [folderCreateBtn addTarget:self action:@selector(createNewFolder) forControlEvents:UIControlEventTouchUpInside];
  27. [self addSubview:folderCreateBtn];
  28. self.folderCreateBtn = folderCreateBtn;
  29. CustomButton *fileSortBtn = [[CustomButton alloc]initCustomBtnWithImageDirection:ImagePostionTop imageViewSize:CGSizeMake(BtnWH, BtnWH) imageLabelMargin:0 titleLabelFont:nil imageIcon:@"file_sort_n" selectIcon:@"file_sort_p" title:nil btnWidth:BtnWH];
  30. [fileSortBtn addTarget:self action:@selector(sortFile) forControlEvents:UIControlEventTouchUpInside];
  31. [self addSubview:fileSortBtn];
  32. self.fileSortBtn = fileSortBtn;
  33. //WithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SearchBarHeight)
  34. CustomSearchBar *searchBar = [[CustomSearchBar alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CloudStorageBarHeight)];
  35. [searchBar setImage:nil forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
  36. searchBar.placeholder = @"搜索";
  37. searchBar.delegate = self;
  38. [self addSubview:searchBar];
  39. // 添加 searchbar 到 headerview
  40. self.searchBar = searchBar;
  41. // NSArray *segtitiles = @[@"全部",@"图片",@"文档",@"视频",@"音频",@"其他"];
  42. // UISegmentedControl *segmentControl = [[UISegmentedControl alloc]initWithItems:segtitiles];
  43. // segmentControl.apportionsSegmentWidthsByContent = NO;
  44. // segmentControl.tintColor = [UIColor clearColor];//去掉颜色,现在整个segment都看不见
  45. // segmentControl.backgroundColor = [UIColor colorWithRed:0.969 green:0.969 blue:0.961 alpha:1.000];
  46. // NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:14],
  47. // NSForegroundColorAttributeName: [UIColor colorWithRed:0.000 green:0.475 blue:1.000 alpha:1.000]};
  48. // [segmentControl setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//设置文字属性
  49. // NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:14],
  50. // NSForegroundColorAttributeName: [UIColor colorWithWhite:0.510 alpha:1.000]};
  51. // [segmentControl setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
  52. //
  53. // segmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
  54. // [segmentControl addTarget:self action:@selector(segmentaction:) forControlEvents:UIControlEventValueChanged];
  55. //
  56. //
  57. // //[self.segmentControl addTarget:self action:@selector(segmentaction:) forControlEvents:UIControlEventValueChanged];
  58. // segmentControl.selectedSegmentIndex = 0;
  59. // [self addSubview:segmentControl];
  60. // self.segmentControl = segmentControl;
  61. }
  62. return self;
  63. }
  64. - (void)createNewFolder
  65. {
  66. if (self.barNewFolderBlock) {
  67. self.barNewFolderBlock();
  68. }
  69. }
  70. - (void)sortFile
  71. {
  72. __weak typeof(self)weakSelf = self;
  73. [FTPopOverMenu showForSender:self.fileSortBtn withMenuArray:@[@"按文件名称排序",@"按时间倒序排序"] doneBlock:^(NSInteger selectedIndex) {
  74. if (weakSelf.barSortBlock) {
  75. weakSelf.barSortBlock((SortType)selectedIndex);
  76. }
  77. } dismissBlock:^{
  78. }];
  79. // [FTPopOverMenu showForSender:self.fileSortBtn withMenuArray:@[@"按文件名称排序",@"按时间倒序排序"] imageNameArray:nil doneBlock:^(NSInteger selectedIndex) {
  80. }
  81. - (void)segmentaction:(UISegmentedControl *)segController
  82. {
  83. if (self.fileClassBlock) {
  84. self.fileClassBlock((CloudStorageBarFileType)segController.selectedSegmentIndex);
  85. }
  86. }
  87. - (void)giveUpSearch
  88. {
  89. [self.searchBar resignFirstResponder];
  90. }
  91. #pragma mark --
  92. #pragma mark --searchbardelegate
  93. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
  94. {
  95. //以后隐藏
  96. if ([self.delegate respondsToSelector:@selector(searchBarPrepareToSearch)]) {
  97. [self.delegate searchBarPrepareToSearch];
  98. }
  99. searchBar.showsCancelButton = YES;
  100. return YES;
  101. }
  102. //
  103. //- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  104. //{
  105. //
  106. //}
  107. //
  108. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  109. {
  110. [self.searchBar resignFirstResponder];
  111. if ([self.delegate respondsToSelector:@selector(searchBarStartSearch:withSearchContent:)]) {
  112. [self.delegate searchBarStartSearch:searchBar withSearchContent:searchBar.text];
  113. }
  114. }
  115. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  116. {
  117. if ([self.delegate respondsToSelector:@selector(searchBarCancerSearch)]) {
  118. [self.delegate searchBarCancerSearch];
  119. }
  120. searchBar.showsCancelButton = NO;
  121. [self.searchBar resignFirstResponder];
  122. }
  123. - (void)layoutSubviews
  124. {
  125. [super layoutSubviews];
  126. self.folderCreateBtn.frame = CGRectMake(MarginX,(SearchBarH - BtnWH )/2.0f, BtnWH, BtnWH);
  127. self.fileSortBtn.frame = CGRectMake(CGRectGetMaxX(self.folderCreateBtn.frame) + MarginX, (SearchBarH - BtnWH )/2.0f,BtnWH, BtnWH);
  128. self.searchBar.frame = CGRectMake(CGRectGetMaxX(self.fileSortBtn.frame), 0, self.frame.size.width - self.folderCreateBtn.frame.size.width - self.fileSortBtn.frame.size.width - 2 * MarginX, SearchBarH);
  129. // self.segmentControl.frame = CGRectMake(0, CGRectGetMaxY(self.searchBar.frame), self.frame.size.width, SegmentControllH);
  130. }
  131. @end