float x = [self xPositionFromSliderValue:self.navigationSlider]; UILabel* label=[[UILabel alloc]initWithFrame:CGRectMake(x, 42, 30, 20)]; [label setBackgroundColor:[UIColor colorWithRed:0.494 green:0 blue:0.835 alpha:1]]; [label setText:_playTimer.text]; [label setTextColor:[UIColor whiteColor]]; [label setText:_playTimer.text]; [label setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:12]]; [self.navigationSlider addSubview:label]; 

This is how I move the Label, it leaves a trail behind it. How to remove it?

    1 answer 1

    You do not move UILabel , you create new ones and put them in a new position, so this is not quite a loop, this is UILabel old UILabel

    To move a visual object try saving a pointer to it.

     @property (nonatomic, weak) UILabel *label; 

    then move

     self.label.center = CGPointMake(newX, newY); 

    To move an object with animation, place the movement code in the animation block:

     [UIView animateWithDuration: 0.2 animations:^{ self.label.center = CGPointMake(newX, newY); } completion:nil];