在UINavigationBar上删除渐变

如何删除UINavigationBar上的默认渐变? 我设置了哪些属性来做到这一点?

您可以通过将此代码popup到具有导航栏的类中来删除渐变并设置您自己的纯色。 您可以将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