TOScrollBar.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // TOScrollBar.h
  3. //
  4. // Copyright 2016-2017 Timothy Oliver. All rights reserved.
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to
  8. // deal in the Software without restriction, including without limitation the
  9. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. // sell copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  21. // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #import <UIKit/UIKit.h>
  23. #import "UIScrollView+TOScrollBar.h"
  24. typedef NS_ENUM(NSInteger, TOScrollBarStyle) {
  25. TOScrollBarStyleDefault,
  26. TOScrollBarStyleDark
  27. };
  28. NS_ASSUME_NONNULL_BEGIN
  29. @interface TOScrollBar : UIView
  30. /* The visual style of the scroll bar, either light or dark */
  31. @property (nonatomic, assign) TOScrollBarStyle style;
  32. /** Aligns the scroll bar to the top of the scroll view content offset.
  33. Set this to `YES` when using this in a view controller with iOS 11 large titles. */
  34. @property (nonatomic, assign) BOOL insetForLargeTitles;
  35. /** The amount of padding above and below the scroll bar (Only top and bottom values are counted. Default is {20,20} ) */
  36. @property (nonatomic, assign) UIEdgeInsets verticalInset;
  37. /** The inset, in points of the middle of track from the edge of the scroll view */
  38. @property (nonatomic, assign) CGFloat edgeInset;
  39. /** The tint color of the track */
  40. @property (nonatomic, strong) UIColor *trackTintColor;
  41. /** The width in points, of the track (Default value is 2.0) */
  42. @property (nonatomic, assign) CGFloat trackWidth;
  43. /** The tint color of the handle (Defaults to the system tint color) */
  44. @property (nonatomic, strong, nullable) UIColor *handleTintColor;
  45. /** The width in points, of the handle. (Default value is 4.0) */
  46. @property (nonatomic, assign) CGFloat handleWidth;
  47. /** The minimum height in points the handle may be in relation to the content height. (Default value is 64.0) */
  48. @property (nonatomic, assign) CGFloat handleMinimiumHeight;
  49. /** The user is currently dragging the handle */
  50. @property (nonatomic, assign, readonly) BOOL dragging;
  51. /** The minimum required scale of the scroll view's content height before the scroll bar is shown (Default is 5.0) */
  52. @property (nonatomic, assign) CGFloat minimumContentHeightScale;
  53. /** The scroll view in which this scroll bar has been added. */
  54. @property (nonatomic, weak, readonly) UIScrollView *scrollView;
  55. /** When enabled, the scroll bar will only respond to direct touches to the handle control.
  56. Touches to the track will be passed to the UI controls beneath it.
  57. Default is NO. */
  58. @property (nonatomic, assign) BOOL handleExclusiveInteractionEnabled;
  59. /**
  60. Creates a new instance of the scroll bar view
  61. @param style The initial style of the scroll bar upon creation
  62. */
  63. - (instancetype)initWithStyle:(TOScrollBarStyle)style;
  64. /**
  65. Adds the scroll bar to a scroll view
  66. @param scrollView The scroll view that will receive this scroll bar
  67. */
  68. - (void)addToScrollView:(UIScrollView *)scrollView;
  69. /**
  70. Removes the scroll bar from the scroll view and resets the scroll view's state
  71. */
  72. - (void)removeFromScrollView;
  73. /**
  74. If added to a table view, this convienience method will compute the appropriate
  75. inset values for the table separator so they don't underlap the scroll bar
  76. @param inset The original separator inset value of the table view
  77. */
  78. - (UIEdgeInsets)adjustedTableViewSeparatorInsetForInset:(UIEdgeInsets)inset;
  79. /**
  80. If added to a table view, this convienience method will compute the appropriate
  81. insets values for each cell's layout margins in order to appropriately push the cell's
  82. content inwards
  83. @param layoutMargins The current `layoutMargins` value of the `UITableViewCell` instance.
  84. @param offset If desired, any additional horizontal offset for this specific use case
  85. */
  86. - (UIEdgeInsets)adjustedTableViewCellLayoutMarginsForMargins:(UIEdgeInsets)layoutMargins manualOffset:(CGFloat)offset;
  87. /**
  88. Shows or hides the scroll bar from the scroll view with an optional animation
  89. */
  90. - (void)setHidden:(BOOL)hidden animated:(BOOL)animated;
  91. @end
  92. NS_ASSUME_NONNULL_END