- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
RootViewController*root=[[RootViewController alloc]init];
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:root];
//[[UINavigationBar appearance]setTintColor:[UIColor redColor]];
//ios 7以后使用BarTintColor 改变导航栏的背景颜色
// [[UINavigationBar appearance]setBarTintColor:[UIColor cyanColor]];
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];
//设置图片
//[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"u27.png"] forBarMetrics:UIBarMetricsDefault];
//导航条上跳转之后的 返回字体的颜色
[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setTranslucent:YES];
self.window.rootViewController=nav;
//状态条变成高亮的(白色)
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
//状态条隐藏
// [UIApplication sharedApplication].statusBarHidden=YES;
//导航条隐藏
// [self.navigationController setNavigationBarHidden:YES];
[self.window makeKeyAndVisible];
return YES;
}
//或者在info .plist中添加一个key View controller-based status bar appearance并将它改成 NO; ----设置成高亮状态
//在info .plist中添加一个key Status bar is initially hidden 将他改为YES 就能隐藏状态栏(启动app以后的所有的状态栏)
#import "RootViewController.h"
#import "nextViewController.h"
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
@interface RootViewController ()
{
nextViewController*next;
}
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
next=[[nextViewController alloc]init];
UIButton*btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(30, 30, 30, 30);
btn.backgroundColor=[UIColor blackColor];
[btn addTarget:self action:@selector(pressBtn) forControlEvents:UIControlEventTouchUpInside];
[btn setImage:[UIImage imageNamed:@"u2.png"] forState:UIControlStateNormal];
self.navigationItem.title=@"test";
// [self.navigationItem setTitle:@"ssss"]; 都行
//改变标题栏字体的大小和颜色
//也可以创建一个label 把label 添加到导航条上,然后设置透明度
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
UIBarButtonItem*item=[[UIBarButtonItem alloc]initWithCustomView:btn];
self.navigationItem.leftBarButtonItem=item;
//导航条隐藏
// [self.navigationController setNavigationBarHidden:YES];
//[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
}
-(void)viewWillAppear:(BOOL)animated
{
//不同界面的导航条颜色变化
// self.navigationController.navigationBar.translucent=YES;
self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
}
-(void)pressBtn
{
[self.navigationController pushViewController:next animated:YES];
}
#import "nextViewController.h"
@interface nextViewController ()
@end
@implementation nextViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)viewWillAppear:(BOOL)animated
{
//不同界面的导航条颜色变化
// self.navigationController.navigationBar.translucent=YES;
self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];
}
![]()
![]()