如何在UINavigationBar上獲得磨砂顏色而不是閃亮的外觀?如何在UINavigationBar上獲得「無光澤」顏色?
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
如何在UINavigationBar上獲得磨砂顏色而不是閃亮的外觀?如何在UINavigationBar上獲得「無光澤」顏色?
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
有沒有內置的方式來做到這一點。使用tintColor
將始終使您獲得默認的「閃亮」外觀。另一種方法是使用here中描述的技術自行繪製條形圖,以獲得所需的外觀。
我用簡單的方法類UINavigationBar的:
@implementation UINavigationBar (UINavigationBarWithoutShiny)
- (void)drawRect:(CGRect)rect {}
@end
在此之後,我可以使用UINavigationBar的視圖的只是背景色:
self.navigationController.navigationBar.backgroundColor = [UIColor greenColor];
它僅適用於iOS 4.x,適用於iOS5我使用setTintColor: – buh
FWIW,似乎大多數投票和接受的答案是**不是一個好主意,因爲它顯然(請參閱評論)在iOS5中不起作用。 UINavigationBar必須是子類,而不是用覆蓋'drawRect的類別擴展:' –
爲什麼是子類?在iOS 5中,有一個方法'setBackgroundImage:forBarMetrics:'所以在你的類別中,爲什麼不先執行'respondsToSelector:'檢查然後使用適當的方法? –