SMPageControl.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // SMPageControl.h
  3. // SMPageControl
  4. //
  5. // Created by Jerry Jones on 10/13/12.
  6. // Copyright (c) 2012 Spaceman Labs. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. typedef NS_ENUM(NSUInteger, SMPageControlAlignment) {
  10. SMPageControlAlignmentLeft = 1,
  11. SMPageControlAlignmentCenter,
  12. SMPageControlAlignmentRight
  13. };
  14. typedef NS_ENUM(NSUInteger, SMPageControlVerticalAlignment) {
  15. SMPageControlVerticalAlignmentTop = 1,
  16. SMPageControlVerticalAlignmentMiddle,
  17. SMPageControlVerticalAlignmentBottom
  18. };
  19. typedef NS_ENUM(NSUInteger, SMPageControlTapBehavior) {
  20. SMPageControlTapBehaviorStep = 1,
  21. SMPageControlTapBehaviorJump
  22. };
  23. @interface SMPageControl : UIControl
  24. @property (nonatomic) NSInteger numberOfPages;
  25. @property (nonatomic) NSInteger currentPage;
  26. @property (nonatomic) CGFloat indicatorMargin UI_APPEARANCE_SELECTOR; // deafult is 10
  27. @property (nonatomic) CGFloat indicatorDiameter UI_APPEARANCE_SELECTOR; // deafult is 6
  28. @property (nonatomic) CGFloat minHeight UI_APPEARANCE_SELECTOR; // default is 36, cannot be less than indicatorDiameter
  29. @property (nonatomic) SMPageControlAlignment alignment UI_APPEARANCE_SELECTOR; // deafult is Center
  30. @property (nonatomic) SMPageControlVerticalAlignment verticalAlignment UI_APPEARANCE_SELECTOR; // deafult is Middle
  31. @property (nonatomic, strong) UIImage *pageIndicatorImage UI_APPEARANCE_SELECTOR;
  32. @property (nonatomic, strong) UIImage *pageIndicatorMaskImage UI_APPEARANCE_SELECTOR; // ignored if pageIndicatorImage is set
  33. @property (nonatomic, strong) UIColor *pageIndicatorTintColor UI_APPEARANCE_SELECTOR; // ignored if pageIndicatorImage is set
  34. @property (nonatomic, strong) UIImage *currentPageIndicatorImage UI_APPEARANCE_SELECTOR;
  35. @property (nonatomic, strong) UIColor *currentPageIndicatorTintColor UI_APPEARANCE_SELECTOR; // ignored if currentPageIndicatorImage is set
  36. @property (nonatomic) BOOL hidesForSinglePage; // hide the the indicator if there is only one page. default is NO
  37. @property (nonatomic) BOOL defersCurrentPageDisplay; // if set, clicking to a new page won't update the currently displayed page until -updateCurrentPageDisplay is called. default is NO
  38. @property (nonatomic) SMPageControlTapBehavior tapBehavior; // SMPageControlTapBehaviorStep provides an increment/decrement behavior exactly like UIPageControl. SMPageControlTapBehaviorJump allows specific pages to be selected by tapping their respective indicator. Default is SMPageControlTapBehaviorStep
  39. - (void)updateCurrentPageDisplay; // update page display to match the currentPage. ignored if defersCurrentPageDisplay is NO. setting the page value directly will update immediately
  40. - (CGRect)rectForPageIndicator:(NSInteger)pageIndex;
  41. - (CGSize)sizeForNumberOfPages:(NSInteger)pageCount;
  42. - (void)setImage:(UIImage *)image forPage:(NSInteger)pageIndex;
  43. - (void)setCurrentImage:(UIImage *)image forPage:(NSInteger)pageIndex;
  44. - (void)setImageMask:(UIImage *)image forPage:(NSInteger)pageIndex;
  45. - (UIImage *)imageForPage:(NSInteger)pageIndex;
  46. - (UIImage *)currentImageForPage:(NSInteger)pageIndex;
  47. - (UIImage *)imageMaskForPage:(NSInteger)pageIndex;
  48. - (void)updatePageNumberForScrollView:(UIScrollView *)scrollView;
  49. - (void)setScrollViewContentOffsetForCurrentPage:(UIScrollView *)scrollView animated:(BOOL)animated;
  50. #pragma mark - UIAccessibility
  51. // SMPageControl mirrors UIPageControl's standard accessibility functionality by default.
  52. // Basically, the accessibility label is set to "[current page index + 1] of [page count]".
  53. // SMPageControl extends UIPageControl's functionality by allowing you to name specific pages. This is especially useful when using
  54. // the per-page indicator images, and allows you to provide more context to the user.
  55. - (void)setName:(NSString *)name forPage:(NSInteger)pageIndex;
  56. - (NSString *)nameForPage:(NSInteger)pageIndex;
  57. @end