Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For future reference, here's my somewhat hasty solution for animating tint. I'm sure there are more clever ways of doing this with categories and a struct for the rgb values yadda yadda. I was in a hurry, OK?!</p> <p><strong>UITabBarController subclass:</strong></p> <pre><code>@interface BaseNavigationController : UINavigationController { NSTimer * tintTimer; UIColor * targetColor; } -(void)changeTintTo:(UIColor*)color; -(void)animateTint; </code></pre> <p>.</p> <pre><code>-(void)changeTintTo:(UIColor*)color; { targetColor = [color retain]; [tintTimer invalidate]; tintTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0 target:self selector:@selector(animateTint) userInfo:nil repeats:YES]; } -(void)animateTint; { UIColor * currentColor = self.navigationBar.tintColor; CGFloat red, green, blue, alpha; [currentColor getRed:&amp;red green:&amp;green blue:&amp;blue alpha:&amp;alpha]; CGFloat targetRed, targetGreen, targetBlue, targetAlpha; [targetColor getRed:&amp;targetRed green:&amp;targetGreen blue:&amp;targetBlue alpha:&amp;targetAlpha]; CGFloat newRed = red + ((targetRed - red)*.2); UIColor * newColor = [UIColor colorWithRed:newRed green:green + ((targetGreen - green)*.2) blue:blue + ((targetBlue - blue)*.2) // the .2 adjusts the fade speed alpha:1.0]; if( (newRed &lt; targetRed &amp;&amp; newRed &gt;= targetRed-0.01) || (newRed &gt; targetRed &amp;&amp; newRed &lt;= targetRed+0.01) ) { newColor = targetColor; [targetColor autorelease]; [tintTimer invalidate]; tintTimer = nil; targetColor = nil; } self.navigationBar.tintColor = newColor; } </code></pre>
 

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