关键方法。
if ([UINavigationBar instancesRespondToSelector:@selector(setShadowImage:)])
{
[[UINavigationBar appearance] setShadowImage:[UIImage imageWithColor:[UIColor clearColor] size:CGSizeMake(320, 3)]];
}
还有uiimage的一个类目方法。
下面是全部的代码。。。。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
Navbar *bar = (Navbar *)self.navigationController.navigationBar;
//关键是这几句。。。。。
[bar setTranslucent:NO];
if (IS_IOS_7) {
// [bar setTintColor:k_nav_bgColor];
// [bar setBarTintColor:k_nav_bgColor];
///用上面的两句话也挺好,但是会用下面的一条黑线。。。。。
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"aaaaa.png"] forBarMetrics:UIBarMetricsDefault];
}
}else{
[bar setBackgroundImage:kImageNamed(@"bg_nav.png") forBarMetrics:UIBarMetricsDefault];
[bar.layer setMasksToBounds:YES];
[UIApplicationsharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
}
// [self followScrollView:self.view]; //是否隐藏导航栏用的 。这个目前不能用,里面有代码
if ([UINavigationBar instancesRespondToSelector:@selector(setShadowImage:)])
{
[[UINavigationBarappearance] setShadowImage:[UIImageimageWithColor:[UIColorclearColor] size:CGSizeMake(320, 3)]];
}
}
给UIImage添加的类别
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
{
@autoreleasepool {
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context,
color.CGColor);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
}