如何在UILabel iPhone sdk中提供选框效果?

时间:2011-11-18 12:41:43

标签: iphone ios uikit uilabel

我想为UILabel添加自动滚动效果。

我试图在互联网上找到任何代码,但没有成功。

可以在http://blog.stormyprods.com/2009/10/simple-scrolling-uilabel-for-iphone.html找到一些代码。讨论的解决方案通过IBOutlet添加UIScrollview来进行自动滚动。

**我已经编辑了这个问题,以便给出的部分更容易理解 - 但问题仍然不清楚,我恐怕**(直到)

1 个答案:

答案 0 :(得分:1)

我不是很确定,但我认为你必须按帧进行动画。当你设置标签的坐标时,将变量设置为x,y而不是参数1和2的值。 并将其放入动画计时器中,并改变x和y的值。

类似的代码,它也适用于图像,你也可以为标签做: -

// 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];

我希望它可以帮助你...... :)