连续滚动UILabel就像选框一样

时间:2012-06-29 04:16:20

标签: objective-c ios cocoa-touch uilabel marquee

以下是我的代码,用于滚动UILabel水平,使其显示为选框效果。但是动画开始于标签位于中心并滚动直到它的宽度,并再次从中心滚动统计数据。我想要从左到右连续滚动字幕。任何身体都可以帮助我。

-(void)loadLabel{

    if (messageView) {
        [messageView removeFromSuperview];
    }

    NSString *theMessage = text;
    messageSize = [theMessage sizeWithFont:font];
    messageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, messageSize.width, 916)]; //x,y,width,height
    [messageView setClipsToBounds:NO]; // With This you prevent the animation to be drawn outside the bounds.
    [self.view addSubview:messageView];
    lblTime = [[RRSGlowLabel alloc] initWithFrame:CGRectMake(0, 0, messageSize.width, 916)]; //x,y,width,height
    [lblTime setBackgroundColor:[UIColor yellowColor]];
    lblTime.font = font;
    [lblTime setText:theMessage];
    lblTime.glowOffset = CGSizeMake(0.0, 0.0);
    lblTime.glowAmount = 90.0;
    lblTime.glowColor = color;
    [lblTime setClipsToBounds:NO];
    [lblTime setTextColor:color];
    [lblTime setTextAlignment:UITextAlignmentLeft];
    lblTime.frame = messageView.bounds ; //x,y,width,height
    [messageView addSubview:lblTime];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:speed];

    [UIView setAnimationRepeatCount:HUGE_VALF];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:messageView cache:YES];
    lblTime.frame = CGRectMake(-messageSize.width, 45, messageSize.width, 916); //x,y,width,height
    [UIView commitAnimations];
}

0 个答案:

没有答案