secendelegate.m
#import "SceneDelegate.h" #import "VCRoot.h" @interface SceneDelegate () @end @implementation SceneDelegate - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene]; self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); UINavigationController* nav=[[UINavigationController alloc] initWithRootViewController:[[VCRoot alloc]init]]; self.window.rootViewController=nav; [self.window makeKeyAndVisible]; }
VCRoot.m
#import "VCRoot.h" @interface VCRoot () @end @implementation VCRoot - (void)viewDidLoad { [super viewDidLoad]; // self.view.backgroundColor=[UIColor yellowColor]; //默认 半透明 self.navigationController.navigationBar.barStyle=UIBarStyleDefault; // 设置 透明 self.navigationController.navigationBar.translucent=NO; // 设置 导航栏的颜色 self.navigationController.navigationBar.barTintColor=[UIColor redColor]; //设置导航栏元素风格 self.navigationController.navigationBar.tintColor=[UIColor greenColor]; //隐藏导航栏 // self.navigationController.navigationBar.hidden=YES; // self.navigationController.navigationBarHidden=YES; self.title=@"根视图"; UIBarButtonItem* btn = [[UIBarButtonItem alloc]initWithTitle:@"右侧按钮" style:UIBarButtonItemStyleDone target:self action:nil]; self.navigationItem.rightBarButtonItem=btn; UIBarButtonItem* btn01=[[UIBarButtonItem alloc]initWithTitle:@"left" style:UIBarButtonItemStylePlain target:nil action:nil]; UIBarButtonItem* btn02=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:nil action:nil]; UIButton* btnImage = [UIButton buttonWithType:UIButtonTypeCustom]; [btnImage setImage:[UIImage imageNamed:@"Processsettings"] forState:UIControlStateNormal]; btnImage.frame=CGRectMake(0, 0, 60, 60); UIBarButtonItem* btn03=[[UIBarButtonItem alloc]initWithCustomView:btnImage]; NSArray* arrayBtns=[NSArray arrayWithObjects:btn01, btn02,btn03,nil]; self.toolbarItems=arrayBtns; } @end