-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathCBAutoScrollLabel.h
More file actions
93 lines (78 loc) · 3.1 KB
/
CBAutoScrollLabel.h
File metadata and controls
93 lines (78 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// CBAutoScrollLabel.h
// CBAutoScrollLabel
//
// Created by Brian Stormont on 10/21/09.
// Updated/Modernized by Christopher Bess on 2/5/12
//
// Copyright 2009 Stormy Productions. All rights reserved.
//
// Originally from: http://blog.stormyprods.com/2009/10/simple-scrolling-uilabel-for-iphone.html
//
// Permission is granted to use this code free of charge for any project.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, CBAutoScrollDirection) {
CBAutoScrollDirectionRight,
CBAutoScrollDirectionLeft
};
@interface CBAutoScrollLabel : UIView <UIScrollViewDelegate>
@property (nonatomic) CBAutoScrollDirection scrollDirection;
@property (nonatomic) float scrollSpeed; // pixels per second
@property (nonatomic) NSTimeInterval pauseInterval;
@property (nonatomic) NSInteger labelSpacing; // pixels
/**
* The animation options used when scrolling the UILabels.
* @discussion UIViewAnimationOptionAllowUserInteraction is always applied to the animations.
*/
@property (nonatomic) UIViewAnimationOptions animationOptions;
/**
* Returns YES, if it is actively scrolling, NO if it has paused or if text is within bounds (disables scrolling).
*/
@property (nonatomic, readonly) BOOL scrolling;
@property (nonatomic, assign, readonly) BOOL shouldScroll;
@property (nonatomic) CGFloat fadeLength;
// UILabel properties
@property (nonatomic, copy) NSString *text;
@property (nonatomic, copy) NSAttributedString *attributedText;
@property (nonatomic, strong) UIColor *textColor;
@property (nonatomic, strong) UIFont *font;
@property (nonatomic, strong) UIColor *shadowColor;
@property (nonatomic) CGSize shadowOffset;
@property (nonatomic) NSTextAlignment textAlignment; // only applies when not auto-scrolling
/**
* Lays out the scrollview contents, enabling text scrolling if the text will be clipped.
* @discussion Uses [scrollLabelIfNeeded] internally.
*/
- (void)refreshLabels;
/**
* Set the text to the label and refresh labels, if needed.
* @discussion Useful when you have a situation where you need to layout the scroll label after it's text is set.
*/
- (void)setText:(NSString *)text refreshLabels:(BOOL)refresh;
- (void)setAttributedText:(NSAttributedString *)theText refreshLabels:(BOOL)refresh;
/**
* Initiates auto-scroll if the label width exceeds the bounds of the scrollview.
*/
- (void)scrollLabelIfNeeded;
/**
* Stops auto-scroll after the current cycle has been finished.
*/
- (void)stopScrollingAfterCurrentCycle;
/**
* Stops auto-scroll immediately and resets the scroll position to the start.
* @param animated Defines whether the scrolling to the beginning should be animated or not.
*/
- (void)stopScrollingImmediatelyAnimated:(BOOL)animated;
/**
* (Re)enables auto-scroll. If auto-scroll is already enabled, calling this method has no effect.
*/
- (void)reenableAutoScroll;
/**
* Observes UIApplication state notifications to auto-restart scrolling and watch for
* orientation changes to refresh the labels.
* @discussion Must be called to observe the notifications. Calling multiple times will still only
* register the notifications once.
*/
- (void)observeApplicationNotifications;
@end