UINavigationBar(导航栏)设置标题/颜色/背景/透明度状态栏颜色

①设置标题:self.navigationItem.title=@:UINavigationBar使用总结"

②设置导航栏标题颜色:[bar setTitleTextAttributes @{NSForegroundColorAttributedName:[UIColor whiteColor}];

(其他textAttributes属性包括:UITextAttributeFont字体;UITextAttributedTextColor文字颜色;UITextAttributeTextShadowColor文字阴影颜色;UITextAttributeTextShadowOffset偏移用于文本阴影)

③设置导航栏背景颜色:self.navigationControllerBar.barTintColor=[UIColor redColor];

④设置导航栏背景图片:[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Background"] forBarMetrics:UIBarMetricsDefault];

⑤设置导航栏样式:UIStateBarStyleDefault 黑色导航栏,适用于浅色背景

UIStateBarStyleLightContent 白色导航栏,适用于深色背景

实现方式: a)在info.plist中添加一行 UIViewControllerBasedStatusBarAppearance,选择Boolen型,并选择YES

b)在ViewController.h中,添加方法:

-(UIStatusBarStyle)preferredStatusBarStyle

{

return UIStatusBarStyleLightContent;

}

注意:若ViewController由navigationControlller push进来,则还要添加代码:

self.navigationController.navigationBar.barStyle=UIBarStyleBlack;

⑥设置导航栏背景透明:[bar setBackgroundImage:[UIImage image@"bg,.png"] forBarMetrics:UIBarMetricsCompact];(背景随便设,关键是BarMetrics);

设置导航栏背景无透明度(即不显示后面的内容)-->self.extendedLayoutIncludesOpaqueBars=YES;(或者在storyBoard中设置)

⑦设置滚动内容是否会在bar下方显示:automaticallyAdjustScollViewInsets

⑧图片太大会被状态栏位置挡住,需要把多余的图片删除掉:clipsToBounds

self.navigationController.navigationBar.clipsToBounds=YES

⑨页面跳转,就是向导航控制器栈中push或pop一个视图控制器,改变最上面的视图控制器,就会显示这个栈顶的视图控制器的视图

[btn1 addTarget:self action:@selector(jumpTo) forControlEvents:UIControlEventTouchUpInside];(设置按钮的相应方法:addTarget:action:forControlEvents:)

写上相应方法:-(void)jumpTo

{

SecondViewController *senCon1=[[SecondViewController alloc]init];

self.navigationControll pushViewController:seCon1 animates:YES];

}

你可能感兴趣的:(UINavigationBar(导航栏)设置标题/颜色/背景/透明度状态栏颜色)