iOS7之后由于navigationBar.translucent默认是YES,坐标零点默认在(0,0)点 当不透明的时候navigationBar.translucent=no,零点坐标在(0,64);
- (void)setNavigationBar { self.automaticallyAdjustsScrollViewInsets = NO; self.edgesForExtendedLayout = UIRectEdgeTop; // 顶部开始 self.navigationController.navigationBar.translucent = YES; // 导航栏透明 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"barpic1"] forBarMetrics:UIBarMetricsDefault]; // 添加背景颜色(图片)(主要的 如果要把导航栏设置成透明的··用一张透明的图片就好了) //设置导航栏文字为白色 self.navigationController.navigationBar.titleTextAttributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor, nil]; //设置后退按钮为白色 [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]]; //设置后退按钮统一为返回 UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil]; self.navigationItem.backBarButtonItem = item; }
// 去掉导航栏下面的 分割线 if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){ NSArray *list=self.navigationController.navigationBar.subviews; for (id obj in list) { if ([obj isKindOfClass:[UIImageView class]]) { UIImageView *imageView=(UIImageView *)obj; NSArray *list2=imageView.subviews; for (id obj2 in list2) { if ([obj2 isKindOfClass:[UIImageView class]]) { UIImageView *imageView2=(UIImageView *)obj2; imageView2.hidden=YES; } } } } }