TYTabPagerBar.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // TYTabPagerBar.h
  3. // TYPagerControllerDemo
  4. //
  5. // Created by tany on 2017/7/13.
  6. // Copyright © 2017年 tany. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "TYTabPagerBarLayout.h"
  10. NS_ASSUME_NONNULL_BEGIN
  11. @class TYTabPagerBar;
  12. @protocol TYTabPagerBarDataSource <NSObject>
  13. - (NSInteger)numberOfItemsInPagerTabBar;
  14. - (UICollectionViewCell<TYTabPagerBarCellProtocol> *)pagerTabBar:(TYTabPagerBar *)pagerTabBar cellForItemAtIndex:(NSInteger)index;
  15. @end
  16. @protocol TYTabPagerBarDelegate <NSObject>
  17. @optional
  18. // configure layout
  19. - (void)pagerTabBar:(TYTabPagerBar *)pagerTabBar configureLayout:(TYTabPagerBarLayout *)layout;
  20. // if cell wdith is not variable,you can set layout.cellWidth. otherwise ,you can implement this return cell width. cell width not contain cell edge
  21. - (CGFloat)pagerTabBar:(TYTabPagerBar *)pagerTabBar widthForItemAtIndex:(NSInteger)index;
  22. // did select cell item
  23. - (void)pagerTabBar:(TYTabPagerBar *)pagerTabBar didSelectItemAtIndex:(NSInteger)index;
  24. // transition frome cell to cell with animated
  25. - (void)pagerTabBar:(TYTabPagerBar *)pagerTabBar transitionFromeCell:(UICollectionViewCell<TYTabPagerBarCellProtocol> * _Nullable)fromCell toCell:(UICollectionViewCell<TYTabPagerBarCellProtocol> * _Nullable)toCell animated:(BOOL)animated;
  26. // transition frome cell to cell with progress
  27. - (void)pagerTabBar:(TYTabPagerBar *)pagerTabBar transitionFromeCell:(UICollectionViewCell<TYTabPagerBarCellProtocol> * _Nullable)fromCell toCell:(UICollectionViewCell<TYTabPagerBarCellProtocol> * _Nullable)toCell progress:(CGFloat)progress;
  28. @end
  29. @interface TYTabPagerBar : UIView
  30. @property (nonatomic, weak, readonly) UICollectionView *collectionView;
  31. @property (nonatomic, strong) UIView *progressView;
  32. // automatically resized to self.bounds
  33. @property (nonatomic, strong) UIView *backgroundView;
  34. @property (nonatomic, weak, nullable) id<TYTabPagerBarDataSource> dataSource;
  35. @property (nonatomic, weak, nullable) id<TYTabPagerBarDelegate> delegate;
  36. @property (nonatomic, strong) TYTabPagerBarLayout *layout;
  37. @property (nonatomic, assign) BOOL autoScrollItemToCenter;
  38. @property (nonatomic, assign, readonly) NSInteger countOfItems;
  39. @property (nonatomic, assign, readonly) NSInteger curIndex;
  40. @property (nonatomic, assign) UIEdgeInsets contentInset;
  41. - (void)registerClass:(Class)Class forCellWithReuseIdentifier:(NSString *)identifier;
  42. - (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier;
  43. - (__kindof UICollectionViewCell<TYTabPagerBarCellProtocol> *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndex:(NSInteger)index;
  44. - (void)reloadData;
  45. - (void)scrollToItemFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex animate:(BOOL)animate;
  46. - (void)scrollToItemFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex progress:(CGFloat)progress;
  47. - (void)scrollToItemAtIndex:(NSInteger)index atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated;
  48. - (CGFloat)cellWidthForTitle:(NSString * _Nullable)title;
  49. - (CGRect)cellFrameWithIndex:(NSInteger)index;
  50. - (nullable UICollectionViewCell<TYTabPagerBarCellProtocol> *)cellForIndex:(NSInteger)index;
  51. @end
  52. NS_ASSUME_NONNULL_END