1.先说添加吧
AppDelegate.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // 修改导航颜色 [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:100 green:80 blue:50 alpha:1]]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; ViewController *vc = [[ViewController alloc] init]; self.window.rootViewController = vc; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; }
2.自定义导航栏
系统自带的方法 //左边按钮 UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(selectLeftAction:)]; self.navigationItem.leftBarButtonItem = leftButton; //右边按钮 UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(selectRightAction2:)]; self.navigationItem.rightBarButtonItem = rightButton;
自定义按钮图案
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[self scaleToSize:[UIImage imageNamed:@"myselect.png"] size:CGSizeMake(20, 20)] style:UIBarButtonItemStylePlain target:self action:@selector(Actionright:)]; //设置图片大小 - (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{ // 创建一个bitmap的context // 并把它设置成为当前正在使用的context UIGraphicsBeginImageContext(size); // 绘制改变大小的图片 [img drawInRect:CGRectMake(0, 0, size.width, size.height)]; // 从当前context中创建一个改变大小后的图片 UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); // 使当前的context出堆栈 UIGraphicsEndImageContext(); // 返回新的改变大小后的图片 return scaledImage; }
设置push返回按钮的样式
//push返回按钮样式 UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; self.navigationItem.backBarButtonItem = item; //self.navigationController.navigationBar.tintColor = [UIColor grayColor];
自定义标题与导航栏的样式
//修改导航栏标题字体大小和颜色,背景颜色 [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:212/255.0 green:51/255.0 blue:36/255.0 alpha:1]]; [self.navigationController.navigationBar setTitleTextAttributes:@{ NSFontAttributeName:[UIFont systemFontOfSize:17], NSForegroundColorAttributeName:[UIColor whiteColor] }];
这是改变最上边电量图标,时间等颜色
3.关于跳转的一些总结:
(1).push跳转到下一页,会带着自己导航栏一起跳,这里说的导航栏说的是他自定义的导航栏的属性
NextViewController *next =[[NextViewController alloc]init]; [self.navigationController pushViewController:next animated:NO];
(2).push跳转到下一页,下一页隐藏导航栏
//隐藏导航栏 -(void)viewWillAppear:(BOOL)animated{ self.navigationController.navigationBarHidden = YES; }
(3).pop到前面的任何一页面
//返回视图根控制器 [self.navigationController popToRootViewControllerAnimated:YES]; //pop到指定页面 // for (UIViewController *controller in self.navigationController.viewControllers) { // if ([controller isKindOfClass:[NextViewController class]]) { // NextViewController *A =(NextViewController *)controller; // [self.navigationController popToViewController:A animated:YES]; // } // } //其中的NextViewController为想要跳转到的view
(4).present不带导航栏的跳转
HomeViewController *home = [[HomeViewController alloc]init]; [self presentViewController:home animated:YES completion:^{ NSLog(@"Login Success!"); }];
如果是拖页面的话
HomeViewController *home = [self.storyboard instantiateViewControllerWithIdentifier:@"home"]; home.sessionID = self.sessionID; [self presentViewController:home animated:YES completion:^{ NSLog(@"Login Success!"); }];
时间: 2024-10-08 06:57:42