Remove Gradient on UINavigationBar

2020-02-08 10:11发布

How can I remove the default gradient on a UINavigationBar? What property do I set to do this?

1条回答
叛逆
2楼-- · 2020-02-08 10:50

You can remove the gradient and set your own solid color by popping this code into the class that has the navigation bar. You can change the UIColor to whatever color you need. Note that this code needs to be outside of another implementation, so whatever .m file you put it in put it before the @implmentation of the class already implemented in that file.

@implementation UINavigationBar (UINavigationBarCategory)   
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor blueColor];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
CGContextFillRect(context, rect);
}   
@end
查看更多
登录 后发表回答