改变navigationbar的底部线条颜色

时间:2022-03-07 13:27:27

[[UINavigationBar appearance] setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];

CGRect rect = CGRectMake(0.0f, 0.0f, ScreenWidth, 0.5);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, RGBCOLOR(230, 230, 230).CGColor);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[[UINavigationBar appearance]setShadowImage:image];

以上写在了appdelegate中,其他地方没有试

重点来了,一定要两个都设置才可以

setBackgroundImage

setShadowImage