2011-02-05 87 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