我在我的應用程序中創建了滑塊。如何在我的代碼中添加循環。因爲我的標籤文本只滑動一次,但我想在標籤上標註文本重複(循環)。怎麼可能?如何創建標籤文本滑塊
我的標籤滑塊代碼
讓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 –