怎么设置导航栏某个界面的导航栏透明 ios

怎么设置导航栏某个界面的导航栏透明 ios,第1张

在viewWillAppear里面加两行代码

//设置导航栏背景图片为一个空的image,这样就透明

[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]

//去掉透明后导航栏下边的黑边

[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]]

如果不想让其他页面的导航栏变为透明

在viewWillDisappear里面重置一下

[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]

[self.navigationController.navigationBar setShadowImage:nil]

//中间

//self.navigationItem.title = @"标题"

UIView*redView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,140,40)]

redView.backgroundColor= [UIColorredColor]

UIView*greenView = [[UIViewalloc]initWithFrame:CGRectMake(20,5,100,30)]

greenView.backgroundColor= [UIColorgreenColor]

[redViewaddSubview:greenView]

self.navigationItem.titleView= redView

//右边

UIBarButtonItem*rightItem = [[UIBarButtonItemalloc]initWithTitle:@"个人信息"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(goUserInfoVc:)]

UIBarButtonItem*rightItem2 = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCameratarget:nilaction:nil]

self.navigationItem.rightBarButtonItems=@[rightItem,rightItem2]

//左边

UIBarButtonItem*leftItem = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAddtarget:nilaction:nil]

//通过图片创建barButtonItem

//生成一张不受父视图tintColor影响的图片

UIImage*image = [[UIImageimageNamed:@"github_grayscale"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

UIBarButtonItem*leftItem2 = [[UIBarButtonItemalloc]initWithImage:imagestyle:UIBarButtonItemStylePlaintarget:nilaction:nil]

self.navigationItem.leftBarButtonItems=@[leftItem,leftItem2]

//设置导航栏

//self.navigationController.navigationBar.backgroundColor = [UIColor greenColor]

//设置导航栏的背景色

//self.navigationController.navigationBar.barTintColor = [UIColor greenColor]

//设置导航栏的样式

/*

UIBarStyleDefault浅

UIBarStyleBlack深

UIBarStyleBlackTranslucent

*/

self.navigationController.navigationBar.barStyle=UIBarStyleDefault

//设置背景图片不透明

//self.navigationController.navigationBar.translucent = NO

//修改导航左右内容的颜色

self.navigationController.navigationBar.tintColor= [UIColorgrayColor]

//隐藏自带的背景图片

[self.navigationController.navigationBarsetBackgroundImage:[[UIImagealloc]init]forBarMetrics:UIBarMetricsDefault]

//隐藏阴影图片

[self.navigationController.navigationBarsetShadowImage:[[UIImagealloc]init]]

//设置导航的toolBar

//把toolBar显示出来

self.navigationController.toolbarHidden=NO

UIBarButtonItem*toolBarItem = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemPlaytarget:nilaction:nil]

UIBarButtonItem*toolBarItem2 = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemStoptarget:nilaction:nil]

UIBarButtonItem*toolBarItem3 = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdittarget:nilaction:nil]

//创建木棍特效UIBarButtonItem样式Fixed

UIBarButtonItem*toolBarItem4 = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpacetarget:nilaction:nil]

toolBarItem4.width=50

UIBarButtonItem*toolBarItem5 = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpacetarget:nilaction:nil]

toolBarItem5.width=100

//创建d簧特效UIBarButtonItem样式Flexible

UIBarButtonItem*toolBarItem6 = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nilaction:nil]

//50棍- Play - 100棍- Stop -d簧- Edit - 50棍

self.toolbarItems=@[toolBarItem4,toolBarItem, toolBarItem5,toolBarItem2, toolBarItem6,toolBarItem3,toolBarItem4]

附加: 

[self.navigationControllersetNavigationBarHidden:!self.navigationController.navigationBarHiddenanimated:YES]

[self.navigationControllersetToolbarHidden:!self.navigationController.toolbarHiddenanimated:YES]


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11191918.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存