Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<nil key="title"/>
<barButtonItem key="leftBarButtonItem" systemItem="edit" id="BZs-Na-law"/>
<view key="titleView" contentMode="scaleToFill" id="cVi-6H-3sM" customClass="CBAutoScrollLabel">
<rect key="frame" x="112.66666666666669" y="5.6666666666666679" width="150" height="33"/>
<rect key="frame" x="113" y="6" width="150" height="33"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
</view>
Expand Down
18 changes: 10 additions & 8 deletions CBAutoScrollLabel/CBAutoScrollLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ typedef NS_ENUM(NSInteger, CBAutoScrollDirection) {
CBAutoScrollDirectionLeft
};

IB_DESIGNABLE
@interface CBAutoScrollLabel : UIView <UIScrollViewDelegate>

@property (nonatomic) CBAutoScrollDirection scrollDirection;
/// Scroll speed in pixels per second, defaults to 30
@property (nonatomic) float scrollSpeed;
@property (nonatomic) IBInspectable CGFloat scrollSpeed;
@property (nonatomic) NSTimeInterval pauseInterval; // defaults to 1.5
@property (nonatomic) NSInteger labelSpacing; // pixels, defaults to 20
@property (nonatomic) IBInspectable NSInteger labelSpacing; // pixels, defaults to 20

/**
* The animation options used when scrolling the UILabels.
Expand All @@ -38,16 +39,17 @@ typedef NS_ENUM(NSInteger, CBAutoScrollDirection) {
* 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) CGFloat fadeLength; // defaults to 7
@property (nonatomic) IBInspectable CGFloat fadeLength; // defaults to 7

// UILabel properties
@property (nonatomic, strong, nonnull) UIFont *font;
@property (nonatomic, copy, nullable) NSString *text;
@property (nonatomic, strong, nonnull) IBInspectable UIFont *font;
@property (nonatomic, copy, nullable) IBInspectable NSString *text;
@property (nonatomic, copy, nullable) NSAttributedString *attributedText;
@property (nonatomic, strong, nonnull) UIColor *textColor;
@property (nonatomic, strong, nonnull) IBInspectable UIColor *textColor;
@property (nonatomic) NSTextAlignment textAlignment; // only applies when not auto-scrolling
@property (nonatomic, strong, nullable) UIColor *shadowColor;
@property (nonatomic) CGSize shadowOffset;
@property (nonatomic, strong, nullable) IBInspectable UIColor *shadowColor;

@property (nonatomic) IBInspectable CGSize shadowOffset;

/**
* Lays out the scrollview contents, enabling text scrolling if the text will be clipped.
Expand Down
14 changes: 12 additions & 2 deletions CBAutoScrollLabel/CBAutoScrollLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (void)commonInit {
UILabel *label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.autoresizingMask = self.autoresizingMask;

// store labels
[self.scrollView addSubview:label];
[labelSet addObject:label];
Expand All @@ -75,7 +75,11 @@ - (void)commonInit {
_scrollSpeed = kDefaultPixelsPerSecond;
self.pauseInterval = kDefaultPauseTime;
self.labelSpacing = kDefaultLabelBufferSpace;
#if TARGET_INTERFACE_BUILDER
self.textAlignment = NSTextAlignmentCenter;
#else
self.textAlignment = NSTextAlignmentLeft;
#endif
self.animationOptions = UIViewAnimationOptionCurveLinear;
self.scrollView.showsVerticalScrollIndicator = NO;
self.scrollView.showsHorizontalScrollIndicator = NO;
Expand All @@ -91,6 +95,12 @@ - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)prepareForInterfaceBuilder {
[super prepareForInterfaceBuilder];

self.text = @"AutoScrollLabel";
}

- (void)setFrame:(CGRect)frame {
[super setFrame:frame];

Expand Down Expand Up @@ -198,7 +208,7 @@ - (UIFont *)font {
return self.mainLabel.font;
}

- (void)setScrollSpeed:(float)speed {
- (void)setScrollSpeed:(CGFloat)speed {
_scrollSpeed = speed;

[self scrollLabelIfNeeded];
Expand Down