2011-09-07 63 views
0

我將UINavugation條的顏色改爲紅色恢復導航控制器的原始顏色

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

但幾秒後我想將其恢復爲UINavigation條的默認顏色。 請幫助

+0

使用NSTimer幾秒鐘後改變顏色 – booleanBoy

回答

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

將顏色設置爲零。也許這會有所幫助。

self.navigationController.navigationBar.tintColor = nil; 
2

您可以使用

所有的信息;

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

謝謝,

薩蒂亞

1

使用該代碼在幾秒鐘之後調用的方法...

的NSTimer *計時器= [的NSTimer scheduledTimerWithTimeInterval:(1.0)的目標:自選擇器:@selector(changeColor)userInfo:nil repeatats:YES];

[timer fire]; 

在changeColor方法改變顏色爲默認,然後無效定時器。

+0

嗨,我想他是問如何改變顏色爲默認值。 – Satya

+0

是啊謝謝....但他已經提到「幾秒鐘後」.. tatz爲什麼我用NSTimer編寫代碼... – booleanBoy

相關問題