I'm interesting, how can it is possible to make text moving from right to left like a "running news line in TV"?
I can do text moving from right to left (or any other) in UILabel, but this animation moving should be infinity loop, not only one time.
Asked
Active
Viewed 2,869 times
2
-
possible duplicate http://stackoverflow.com/questions/1118626/how-to-add-marquee-to-a-label – iPatel Mar 28 '13 at 14:25
-
http://stackoverflow.com/questions/10327667/uilabel-text-glow-and-marquee – iPatel Mar 28 '13 at 14:27
3 Answers
5
Here's a few:
- https://github.com/caydenliew/CLTickerView
- https://github.com/malcommac/DMScrollingTicker
- https://github.com/MugunthKumar/MKTickerViewDemo
- https://github.com/jeffhodnett/JHTickerView
- https://github.com/cbess/AutoScrollLabel
There's probably more at Cocoa Controls.

woz
- 10,888
- 3
- 34
- 64
1
How about like this:
-(void) animate {
label.center = CGPointMake(self.view.bounds.size.width + label.bounds.size.width/2, label.center.y);
[UIView animateWithDuration:20 delay:0 options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionRepeat) animations:^{
label.center = CGPointMake(0 - label.bounds.size.width/2, label.center.y);
} completion:nil];
}

jjv360
- 4,120
- 3
- 23
- 37
0
// CrawlView.h
#import <UIKit/UIKit.h>
@interface CrawlView : UIScrollView
@property (assign, nonatomic) NSTimeInterval period;
@property (strong, nonatomic) NSMutableArray *messages;
- (void)go;
@end
// CrawlView.m
#define kWORD_SPACE 16.0f
#import "CrawlView.h"
@interface CrawlView ()
@property (assign, nonatomic) CGFloat messagesWidth;
@end
@implementation CrawlView
- (void)buildSubviews {
for (UIView *subview in [self subviews]) {
if ([subview isKindOfClass:[UILabel self]]) {
[subview removeFromSuperview];
}
}
CGFloat xPos = kWORD_SPACE;
for (NSString *message in self.messages) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = message;
CGSize size = [message sizeWithFont:label.font];
CGFloat width = size.width + kWORD_SPACE;
label.frame = CGRectMake(xPos, 0.0, width, self.frame.size.height);
[self addSubview:label];
xPos += width;
}
self.messagesWidth = xPos;
self.contentSize = CGSizeMake(xPos, self.frame.size.height);
self.contentOffset = CGPointMake(-self.frame.size.width, 0.0);
}
- (void)go {
[self buildSubviews];
if (!self.period) self.period = self.messagesWidth / 100;
[UIView animateWithDuration:self.period
delay:0.0
options:UIViewAnimationOptionCurveLinear |UIViewAnimationOptionRepeat
animations:^{
self.contentOffset = CGPointMake(self.messagesWidth, 0.0);
} completion:^(BOOL finished){
[self buildSubviews];}];
}
@end

danh
- 62,181
- 10
- 95
- 136