导航条

导航的标题

self.navigationItem.title = @"二维码";

导航的字体颜色

self.navigationController.navigationBar.tintColor = [UIColor blackColor];

自定义导航上的Item

UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"OK" style:UIBarButtonItemStyleBordered target:self action:@selector(closeKeyboard)];

self.navigationItem.rightBarButtonItem = rightItem;

导航控制器当中的栈的个数(一个数组)

self.navigationController.viewControllers

导航的几个属性

navigationBar:导航条

nav.navigationBar.hidden = YES;

nav.navigationBarHidden = YES;

[nav setNavigationBarHidden:YES animated:YES];

toolbar:工具栏

nav.toolbarHidden = NO;

//隐藏导航条

//self.navigationController.navigationBarHidden = YES;

//设置是否半通明

[self.navigationController.navigationBar setTranslucent:NO];

//设置导航条背景颜色

[self.navigationController.navigationBar setBarTintColor:[UIColor purpleColor]];

//设置导航条的背景图片

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"common.png"] forBarMetrics:UIBarMetricsDefault];

//标题

//self.navigationItem.title = @"firstVC";

[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:20]}];

[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];

self.title = @"firstVC";

[self.navigationController.navigationBar addSubview:_topView];//给导航的navigationBar添加子视图

给导航添加多个rightBarButton

UIButton *rightDeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];

rightDeleteButton.frame = CGRectMake(0, 0, 30, 30);

[rightDeleteButton addTarget:self action:@selector(deleteTask:) forControlEvents:UIControlEventTouchUpInside];

[rightDeleteButton setImage:[UIImage imageNamed:@"删除"] forState:UIControlStateNormal];

UIBarButtonItem *delete = [[UIBarButtonItem alloc] initWithCustomView:rightDeleteButton];

UIButton *rightAddButton = [UIButton buttonWithType:UIButtonTypeCustom];

rightAddButton.frame = CGRectMake(0, 0, 28, 28);

[rightAddButton addTarget:self action:@selector(addTask) forControlEvents:UIControlEventTouchUpInside];

[rightAddButton setImage:[UIImage imageNamed:@"icon-add-bm"] forState:UIControlStateNormal];

UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithCustomView:rightAddButton];

NSArray *rightItems = @[delete,add];

self.navigationItem.rightBarButtonItems = rightItems;

你可能感兴趣的:(导航条)