gpt4 book ai didi

ios - 如何创建标签文本 slider

转载 作者:行者123 更新时间:2023-11-29 00:41:33 24 4
gpt4 key购买 nike

我在我的应用程序中创建了 slider 。如何在我的代码中添加循环。因为我的标签文本只滑动一次,但我想在标签上标记文本重复(循环)。怎么可能?

我的标签 slider 代码

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

}];


}

最佳答案

喜欢

globalCounter=0;
if(des.count>0){
[_label setText:[des objectAtIndex:globalCounter]];
[self changeLable];

}

并调用类似的方法

-(void)changeLable{

if(globalCounter < des.count){



[UIView animateWithDuration:0.
delay:0.5
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{


}
completion:^(BOOL finished) {

if(globalCounter>=des.count){
globalCounter=0;//set counter to zero after it exceeds array count to repeat text change round repeated
}else
{
[_label setText:[des objectAtIndex:globalCounter]];
globalCounter++;
[self performSelector:@selector(changeLable) withObject:nil afterDelay:1];
}




}];
}


}

关于ios - 如何创建标签文本 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39365936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com