美文网首页iOS Developer
IOS 导航栏各种设置,

IOS 导航栏各种设置,

作者: JakieZhang | 来源:发表于2016-12-06 09:08 被阅读155次

//中间

//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;

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

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

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

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

附加: 

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

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

相关文章

网友评论

    本文标题:IOS 导航栏各种设置,

    本文链接:https://www.haomeiwen.com/subject/fanlmttx.html