CBAutoScrollLabel.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // CBAutoScrollLabel.h
  3. // CBAutoScrollLabel
  4. //
  5. // Created by Brian Stormont on 10/21/09.
  6. // Updated/Modernized by Christopher Bess on 2/5/12
  7. //
  8. // Copyright 2009 Stormy Productions. All rights reserved.
  9. //
  10. // Originally from: http://blog.stormyprods.com/2009/10/simple-scrolling-uilabel-for-iphone.html
  11. //
  12. // Permission is granted to use this code free of charge for any project.
  13. //
  14. #import <UIKit/UIKit.h>
  15. /// Specifies the direction of the scroll
  16. typedef NS_ENUM(NSInteger, CBAutoScrollDirection) {
  17. CBAutoScrollDirectionRight,
  18. CBAutoScrollDirectionLeft
  19. };
  20. @interface CBAutoScrollLabel : UIView <UIScrollViewDelegate>
  21. @property (nonatomic) CBAutoScrollDirection scrollDirection;
  22. /// Scroll speed in pixels per second, defaults to 30
  23. @property (nonatomic) float scrollSpeed;
  24. @property (nonatomic) NSTimeInterval pauseInterval; // defaults to 1.5
  25. @property (nonatomic) NSInteger labelSpacing; // pixels, defaults to 20
  26. /**
  27. * The animation options used when scrolling the UILabels.
  28. * @discussion UIViewAnimationOptionAllowUserInteraction is always applied to the animations.
  29. */
  30. @property (nonatomic) UIViewAnimationOptions animationOptions;
  31. /**
  32. * Returns YES, if it is actively scrolling, NO if it has paused or if text is within bounds (disables scrolling).
  33. */
  34. @property (nonatomic, readonly) BOOL scrolling;
  35. @property (nonatomic) CGFloat fadeLength; // defaults to 7
  36. // UILabel properties
  37. @property (nonatomic, strong, nonnull) UIFont *font;
  38. @property (nonatomic, copy, nullable) NSString *text;
  39. @property (nonatomic, copy, nullable) NSAttributedString *attributedText;
  40. @property (nonatomic, strong, nonnull) UIColor *textColor;
  41. @property (nonatomic) NSTextAlignment textAlignment; // only applies when not auto-scrolling
  42. @property (nonatomic, strong, nullable) UIColor *shadowColor;
  43. @property (nonatomic) CGSize shadowOffset;
  44. /**
  45. * Lays out the scrollview contents, enabling text scrolling if the text will be clipped.
  46. * @discussion Uses [scrollLabelIfNeeded] internally.
  47. */
  48. - (void)refreshLabels;
  49. /**
  50. * Set the text to the label and refresh labels, if needed.
  51. * @discussion Useful when you have a situation where you need to layout the scroll label after it's text is set.
  52. */
  53. - (void)setText:(nullable NSString *)text refreshLabels:(BOOL)refresh;
  54. /**
  55. Set the attributed text and refresh labels, if needed.
  56. */
  57. - (void)setAttributedText:(nullable NSAttributedString *)theText refreshLabels:(BOOL)refresh;
  58. /**
  59. * Initiates auto-scroll, if the label width exceeds the bounds of the scrollview.
  60. */
  61. - (void)scrollLabelIfNeeded;
  62. /**
  63. * Observes UIApplication state notifications to auto-restart scrolling and watch for
  64. * orientation changes to refresh the labels.
  65. * @discussion Must be called to observe the notifications. Calling multiple times will still only
  66. * register the notifications once.
  67. */
  68. - (void)observeApplicationNotifications;
  69. @end