如何创建标签文本滑块

How to create Label text 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];

                 }];


 }

试试下面的代码,它可能会有所帮助:

-(void)changeLable{

NSLog(@"globalCounter %d",globalCounter);

[UIView animateWithDuration:1
                      delay:0.5
                    options: UIViewAnimationOptionTransitionCrossDissolve
                 animations:^{

                     [lblTitle setText:[nameArray objectAtIndex:globalCounter]];
                 }
                 completion:^(BOOL finished) {

                    if(globalCounter>nameArray.count)){

                       globalCounter=0;//set counter to zero after it exceeds array count to repeat text change round repeated

                    }else{

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




                 }];
}


}

这是我的回答brother.Sorry我无法立即回答,因为我下载了一些work.I并且运行你的project.First它在你处理错误的数组时崩溃count.So 它限制了我在黑色内部设置条件的 array.After。

-(void)changeLable
{

  NSLog(@"globalCounter %d",globalCounter);

  [UIView animateWithDuration:1
                      delay:0.5
                    options: UIViewAnimationOptionTransitionCrossDissolve
                 animations:^{

                 }
                 completion:^(BOOL finished)
                 {
                     if(globalCounter<des.count)
                     {
                        _label.text = @"";
                        [_label setText:[des objectAtIndex:globalCounter]];
                        globalCounter++;
                     }
                     else
                      globalCounter=0;
                   [self performSelector:@selector(changeLable) withObject:nil afterDelay:1];
            }];
}