2011-02-05 76 views

回答

23

通過將此代碼彈出到具有導航欄的類中,您可以刪除漸變並設置自己的純色。您可以將UIColor更改爲您需要的任何顏色。請注意,此代碼需要在另一個實現之外,因此無論您將它放在哪個.m文件中,都將其放在該文件中已實現的類的@implmentation之前。

@implementation UINavigationBar (UINavigationBarCategory) 
- (void)drawRect:(CGRect)rect { 
UIColor *color = [UIColor blueColor]; 
CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetFillColor(context, CGColorGetComponents([color CGColor])); 
CGContextFillRect(context, rect); 
} 
@end 
+0

在我的應用程序中,我有兩個UINavigationBars。我想要一個保持漸變,我想要一個沒有漸變。我怎麼能這樣做? (此代碼的工作方式,但它使這兩個酒吧沒有梯度) – CodeGuy 2011-02-05 03:32:20