我在我的应用程序中创建了滑块。如何在我的代码中添加循环。因为我的标签文本只滑动一次,但我想在标签上标注文本重复(循环)。怎么可能?如何创建标签文本滑块
我的标签滑块代码
让globalCounter为全局变量
globalCounter=0;
if(nameArray.count>0){
[self changeLable];
}
然后
-(void)changeLable{
if(!(globalCounter<nameArray.count)){
return;
}
NSLog(@"globalCounter %d",globalCounter);
[UIView animateWithDuration:1
delay:0.5
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{
}
completion:^(BOOL finished) {
[lblTitle setText:[nameArray objectAtIndex:globalCounter]];
globalCounter++;
[self performSelector:@selector(changeLable) withObject:nil afterDelay:1];
}];
}
编辑
-(void)changeLable{
if(!(globalCounter<nameArray.count)){
globalCounter=0;
}
NSLog(@"globalCounter %d",globalCounter);
[UIView animateWithDuration:1
delay:0.5
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{
}
completion:^(BOOL finished) {
[lblTitle setText:[nameArray objectAtIndex:globalCounter]];
globalCounter++;
[self performSelector:@selector(changeLable) withObject:nil afterDelay:1];
}];
}
使用的Web视图,而不是标签和使用HTML语法 –
适用于您的文字跑马灯效果使用[MarqueeLabel(https://github.com/cbpowell/MarqueeLabel) – pkc456
http://stackoverflow.com/questions/22397122 /如何移动文本从右到左 - in-ios-programatically/22397613#22397613 –