1

I just want in my application a ticker, i have no idea to implement ticker please tell me.

Thanks

Arun Sharma
  • 230
  • 7
  • 20
  • 1
    You might need to define __a ticker__ a little more for us to help you ;) – deanWombourne Jul 02 '10 at 12:15
  • Whoever voted to close this question should have learned by now that this is the kind of question you ask the poster to clarify, not the kind of question you close for being overly vague. – Ken Bloom Jul 02 '10 at 14:25
  • possible duplicate of [Does anyone have a good way to scroll text off to one side, like a stock ticker in a label on a nib in an iphone app?](http://stackoverflow.com/questions/900425/does-anyone-have-a-good-way-to-scroll-text-off-to-one-side-like-a-stock-ticker-i) – Brad Larson Jul 02 '10 at 14:32

2 Answers2

5

Everything you need to do this is in the SDK, no need to customize at all. I haven't checked this, but you can try the following:

#import <UIKit/UIKit.h>


@interface TickerScrollView : UIScrollView {

    UILabel *textLabel;

}

- (void)displayText:(NSString *)string;
- (void)clearTicker;

@property (nonatomic, retain, readwrite) UILabel *textLabel;

@end

////


#import "TickerScrollView.h"

@interface TickerScrollView()

- (void)initialiseTextLabel;
- (void)clearTicker;

- (void)beginAnimation;

@end


@implementation TickerScrollView

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {

        // Initialization code
        [self setFrame: frame];

        [self setBounces: NO];
        [self setUserInteractionEnabled:NO];

        [self setShowsVerticalScrollIndicator:NO];
        [self setShowsHorizontalScrollIndicator:NO];

        [self initialiseTextLabel];

    }
    return self;
}

- (void)initialiseTextLabel {

    textLabel = [[[UILabel alloc] initWithFrame:self.bounds] autorelease];
    [textLabel setTextAlignment:UITextAlignmentLeft];
    [textLabel setNumberOfLines:1];
    [textLabel sizeToFit];

    [self addSubview:textLabel];
    [self sendSubviewToBack:textLabel];

    [self setScrollEnabled:YES];

}

- (void)displayText:(NSString *)string {

    [self clearTicker];

    [textLabel setText:string];
    [textLabel sizeToFit];

    [self setContentSize:textLabel.frame.size];

    [self beginAnimation];

}

- (void)clearTicker {

    [textLabel setText:@""];
    [textLabel sizeToFit];

    CGPoint origin = CGPointMake(0, 0);
    [self setContentOffset:origin];

}

- (void)beginAnimation {

    CGFloat text_width = textLabel.frame.size.width;
    CGFloat display_width = self.frame.size.width;

    if ( text_width > display_width ) {

        CGPoint origin = CGPointMake(0, 0);
        [self setContentOffset:origin];

        CGPoint terminal_origin = CGPointMake(textLabel.frame.size.width - self.frame.size.width, textLabel.frame.origin.y);
        float duration = (text_width - display_width)/50;

        [UIView beginAnimations:nil context:NULL];

        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
        [UIView setAnimationDelay:1.0];
        [UIView setAnimationDuration:duration];

        [self setContentOffset:terminal_origin];

        [UIView commitAnimations];

    }

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc {

    [textLabel release];
    [super dealloc];

}

@synthesize textLabel;

@end
Ken
  • 30,811
  • 34
  • 116
  • 155
1

Assuming by "Ticker" you mean a horizontally scrolling text:

A ticker is basically just a text string that is moving by having its x coordinate changed continuously. Check this simple tutorial on how to display a label:

http://knol.google.com/k/iphone-sdk-helloworld

Then later you can animate it by using an NSTimer to call a method updating the labels x coordinate continuously.

sinsro
  • 905
  • 7
  • 25
  • No - use the UIView class to control animation. It's all there in the Apple docs. – Ken Dec 07 '10 at 07:06