开发者

Restore the original color of UINavigation Controller

开发者 https://www.devze.com 2023-04-03 08:18 出处:网络
I am changing the color of UINavugation bar to red by self.navigationController.navigationBar.tintColor = [UIColor redColor];

I am changing the color of UINavugation bar to red by

 self.navigationController.navigationBar.tintColor = [UIColor redColor];

but after few seconds I want to restore it to the default co开发者_开发百科lor of UINavigation bar. Please help


Excuse me if I'm oversimplifying the problem, but it seems you could save the default color into a variable, and just set it back when you need to.

You can user a performSelector call to delay the color change.

i.e.

//save the default color into a previously declared UIColor variable
defaultColor =  self.navigationController.navigationBar.tintColor;

//set the new color
self.navigationController.navigationBar.tintColor = [UIColor redColor];

//set the restore method to fire in 3 seconds
[self performSelector:@selector(restoreNavColor) withObject:nil afterDelay:3.0];

and somewhere in your class;

- (void)restoreNavColor {

    self.navigationController.navigationBar.tintColor = defaultColor;

}

This will work regardless of whether you've previously modified the default color of the nav bar or not, and thus should work for your requirement.


You can use

any of these;

self.navigationController.navigationBar.tintColor = nil;
self.navigationController.navigationBar.tintColor = [UIColor clearColor];

Thanks,

Satya


set the color to nil like this. Maybe it would help.

 self.navigationController.navigationBar.tintColor = nil;


Use this code to call the method after a few seconds...

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(changeColor) userInfo:nil repeats:YES];

[timer fire];

in changeColor method change the color to default and then invalidate the timer.

0

精彩评论

暂无评论...
验证码 换一张
取 消