Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The question was asked long ago, but here goes.</p> <p>As said above, textColor for <code>UILabel</code> is not animate-able. A useful trick is to dynamically create in code another <code>UILabel</code>, with the same attributes and position, but with a destination color. You animate the alpha of the new <code>UILabel</code> from 0.0 to 1.0, so it appears like the textColor of the original UILabel is animated. You can remove one of the labels when the animation is completed.</p> <p>Here is an example of a class level method that changes to a different textColor for a short while and changes it back.</p> <pre><code>+(void)colorizeLabelForAWhile:(UILabel *)label withUIColor:(UIColor *)tempColor animated:(BOOL)animated { // We will: // 1) Duplicate the given label as a temporary UILabel with a new color. // 2) Add the temp label to the super view with alpha 0.0 // 3) Animate the alpha to 1.0 // 4) Wait for awhile. // 5) Animate back and remove the temporary label when we are done. // Duplicate the label and add it to the superview UILabel *tempLabel = [[UILabel alloc] init]; tempLabel.textColor = tempColor; tempLabel.font = label.font; tempLabel.alpha = 0; tempLabel.textAlignment = label.textAlignment; tempLabel.text = label.text; [label.superview addSubview:tempLabel]; tempLabel.frame = label.frame; // Reveal the temp label and hide the current label. if (animated) [UIView beginAnimations:nil context:nil]; tempLabel.alpha = 1; label.alpha = 0; if (animated) [UIView commitAnimations]; // Wait for while and change it back. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, FOR_AWHILE_TIME*NSEC_PER_SEC), dispatch_get_main_queue(), ^{ if (animated) { // Change it back animated [UIView animateWithDuration:0.5 animations:^{ // Animate it back. label.alpha = 1; tempLabel.alpha = 0; } completion:^(BOOL finished){ // Remove the tempLabel view when we are done. [tempLabel removeFromSuperview]; }]; } else { // Change it back at once and remove the tempLabel view. label.alpha = 1.0; [tempLabel removeFromSuperview]; } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload