Search code examples
objective-ciosios5uilabelmarquee

How To Make a Marquee UILabel in iOS?


How do I implement a marquee for the iOS UILabel?

Thanks!


Solution

  • I am not very much sure but i think you have to do animation by frame.when you set the co-ordinates for the label put variables like x,y instead of the values of parameters 1 and 2. and put this in a animation timer with changing value of x and y.

    similar code, it is for image you can do it for label also:-

    // Build array of images, cycling through image names
      for (int i = 0; i < IMAGE_COUNT; i++)
        [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"Frame_%d.jpg", i]]];
    
      // Animated images - centered on screen
      animatedImages = [[UIImageView alloc] 
         initWithFrame:CGRectMake(
            (SCREEN_WIDTH / 2) - (IMAGE_WIDTH / 2), 
            (SCREEN_HEIGHT / 2) - (IMAGE_HEIGHT / 2) + STATUS_BAR_HEIGHT,
            IMAGE_WIDTH, IMAGE_HEIGHT)];
      animatedImages.animationImages = [NSArray arrayWithArray:imageArray];
    
      // One cycle through all the images takes 1.5 seconds
      animatedImages.animationDuration = 1.0;
    
      // Repeat forever
      animatedImages.animationRepeatCount = -1;
    
      // Add subview and make window visible
      [window addSubview:animatedImages];
      [window makeKeyAndVisible];
    
      // Start it up
      animatedImages.startAnimating;
    
      // Wait 5 seconds, then stop animation
        [self performSelector:@selector(stopAnimation) withObject:nil afterDelay:1000];
    

    i Hope it helps you.. :)