Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 21 characters in body
Source Link
Paul Peelen
  • 10.4k
  • 15
  • 91
  • 182

I would like to animate the counting of digets in a text calculating upwards. The texts is in a UILabel similar like You have driven for 0.0km and that needs to be changed to You have driven for 143.6km with count animation. Is there any way I can update it animated?

I would like to animate the counting of digets in a text calculating upwards. The texts is in a UILabel similar like You have driven for 0.0km and that needs to be changed to You have driven for 143.6km. Is there any way I can update it animated?

I would like to animate the counting of digets in a text calculating upwards. The texts is in a UILabel similar like You have driven for 0.0km and that needs to be changed to You have driven for 143.6km with count animation. Is there any way I can update it animated?

Added example code
Source Link
Paul Peelen
  • 10.4k
  • 15
  • 91
  • 182

Edit</br/> Here is some of my current code, concerning other animations I already have:

 if (animated) { [UIView beginAnimations:@"scaleAnimation" context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:animationDuration]; } [...] // Amount pointer float xForRedBar = redBarFrame.size.width + redBarFrame.origin.x; CGRect pointerFrame = cell.amountBarPointer.frame; pointerFrame.origin.x = (xForRedBar - (pointerFrame.size.width/2)); if (pointerFrame.origin.x < 12) pointerFrame.origin.x = 12; if (pointerFrame.origin.x >= (308 - (pointerFrame.size.width/2))) pointerFrame.origin.x = 308 - pointerFrame.size.width; [cell.amountBarPointer setFrame:pointerFrame]; // Amount bar CGRect amountBarFrame = cell.amountBar.frame; amountBarFrame.origin.x = 9+(((302 - amountBarFrame.size.width)/100)*self.procentCompleted); [cell.amountBar setFrame:amountBarFrame]; // Amount info text CGRect amountInfoFrame = cell.amountInfo.frame; amountInfoFrame.origin.x = amountBarFrame.origin.x + 2; [cell.amountInfo setFrame:amountInfoFrame]; // Amount text [cell.amountInfo setText:[NSString stringWithFormat:NSLocalizedString(@"You have driven for %@km", nil), self.userAmount]]; [...] if (self.procentCompleted == 0) { [cell.amountBar setAlpha:0]; [cell.amountBarPointer setAlpha:0]; [cell.amountInfo setAlpha:0]; } else { [cell.amountBar setAlpha:1]; [cell.amountBarPointer setAlpha:1]; [cell.amountInfo setAlpha:1]; } if (animated) { [UIView commitAnimations]; } 

Edit</br/> Here is some of my current code, concerning other animations I already have:

 if (animated) { [UIView beginAnimations:@"scaleAnimation" context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:animationDuration]; } [...] // Amount pointer float xForRedBar = redBarFrame.size.width + redBarFrame.origin.x; CGRect pointerFrame = cell.amountBarPointer.frame; pointerFrame.origin.x = (xForRedBar - (pointerFrame.size.width/2)); if (pointerFrame.origin.x < 12) pointerFrame.origin.x = 12; if (pointerFrame.origin.x >= (308 - (pointerFrame.size.width/2))) pointerFrame.origin.x = 308 - pointerFrame.size.width; [cell.amountBarPointer setFrame:pointerFrame]; // Amount bar CGRect amountBarFrame = cell.amountBar.frame; amountBarFrame.origin.x = 9+(((302 - amountBarFrame.size.width)/100)*self.procentCompleted); [cell.amountBar setFrame:amountBarFrame]; // Amount info text CGRect amountInfoFrame = cell.amountInfo.frame; amountInfoFrame.origin.x = amountBarFrame.origin.x + 2; [cell.amountInfo setFrame:amountInfoFrame]; // Amount text [cell.amountInfo setText:[NSString stringWithFormat:NSLocalizedString(@"You have driven for %@km", nil), self.userAmount]]; [...] if (self.procentCompleted == 0) { [cell.amountBar setAlpha:0]; [cell.amountBarPointer setAlpha:0]; [cell.amountInfo setAlpha:0]; } else { [cell.amountBar setAlpha:1]; [cell.amountBarPointer setAlpha:1]; [cell.amountInfo setAlpha:1]; } if (animated) { [UIView commitAnimations]; } 
Source Link
Paul Peelen
  • 10.4k
  • 15
  • 91
  • 182

Update UILabel text animated

I would like to animate the counting of digets in a text calculating upwards. The texts is in a UILabel similar like You have driven for 0.0km and that needs to be changed to You have driven for 143.6km. Is there any way I can update it animated?