3

I need to make marquee UILabel in Xcode. The marquee will scroll from right to left.

I tried CCScrollingLabel also JHTickerView and others. But i can not find simple code with marquee with out any views/arrays/some stupid libraries and others

How to make marquee with UILabel? (UITextField and NSTextField are OK too).

jww
  • 97,681
  • 90
  • 411
  • 885
Evgenii Melnik
  • 69
  • 2
  • 14
  • Have a look at this, May be this is helpfull. http://stackoverflow.com/questions/3232801/itunes-song-title-scrolling-in-cocoa – ADJ Oct 16 '13 at 06:22

1 Answers1

6

You need NSTimer and you need to invoke a method something as :

*This is for OSX, you can easily convert it into iOS, NSTextField and UILabel has different methods.

-(void)awakeFromNib{
    self.myTimer=[NSTimer new];
    self.fullString=@"This is a long string to be shown.";
    [self.label setAlignment:NSRightTextAlignment];
}


-(void)scrollText:(id)parameter{
    static NSInteger len;
    [self.label setStringValue:[self.fullString substringWithRange:NSMakeRange(0, len++)]];

    if (self.label.stringValue.length==self.fullString.length) {
        [self.myTimer invalidate];
    }
}

- (IBAction)buttonAction:(id)sender {

    self.myTimer = [NSTimer scheduledTimerWithTimeInterval:0.2f
                                                    target: self
                                                  selector:@selector(scrollText:)
                                                  userInfo: nil 
                                                   repeats:YES];
}
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • Anoop: If the length of NSTextField is less than the length of NSString, its not displaying the full string. How to display full string. – ADJ Oct 17 '13 at 03:09
  • @ArunPratap: In that case, you need to truncate tail, and then add some logic to append text... – Anoop Vaidya Oct 17 '13 at 07:04