设置导航栏背景图片为一个空的image,这样就透明了,一般情况下我们在
-(void)viewWillAppear:(BOOL)animated{
//设置导航栏为透明
}
-(void)viewWillDisappear:(BOOL)animated{
//还原导航栏的颜色
}
设置导航栏为透明的
设置导航栏背景图片为一个空的image,这样就透明了
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
去掉透明后导航栏下边的黑边
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
还原导航栏的颜色
把之前加上的image设置为nil
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
设置导航栏两边按钮的颜色
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
隐藏返回按钮 右边的文字
[[UIBarButtonItem appearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
导航栏上的自定义标题
//自定义标题视图
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 200, 44)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = [UIFont boldSystemFontOfSize:17];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = @"个人资料";
self.navigationItem.titleView = titleLabel;
导航栏的颜色
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
导航栏的透明度
不透明
self.navigationController.navigationBar.translucent = NO;
半透明
self.navigationController.navigationBar.translucent = YES;
导航栏的跳转
返回到上个页面
[self.navigationController popViewControllerAnimated:YES];
返回到第一个页面
[self.navigationController popToRootViewControllerAnimated:YES];
返回到指定的页面
NSArray *temArray = self.navigationController.viewControllers;
for(UIViewController *temVC in temArray){
if ([temVC isKindOfClass:[VillagersViewController class]]){
[self.navigationController popToViewController:temVC animated:YES];
}
}
网友评论