恢复导航控制器的原始颜色

时间:2011-09-07 06:25:23

标签: iphone

我正在通过

将UINavugation栏的颜色更改为红色
 self.navigationController.navigationBar.tintColor = [UIColor redColor];

但几秒钟后我想将其恢复为UINavigation栏的默认颜色。 请帮忙

4 个答案:

答案 0 :(得分:4)

对不起,如果我过分简化问题,但似乎你可以将默认颜色保存到变量中,并在需要时将其设置回来。

您可以使用performSelector调用来延迟颜色更改。

//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];

在你班上的某个地方;

- (void)restoreNavColor {

    self.navigationController.navigationBar.tintColor = defaultColor;

}

无论您之前是否修改过导航栏的默认颜色,都可以使用,因此可以满足您的要求。

答案 1 :(得分:2)

您可以使用

其中任何一个;

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

谢谢,

萨蒂亚

答案 2 :(得分:1)

将颜色设置为nil。也许它会有所帮助。

 self.navigationController.navigationBar.tintColor = nil;

答案 3 :(得分:1)

使用此代码几秒钟后调用该方法......

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

[timer fire];

在changeColor方法中将颜色更改为默认值,然后使计时器无效。