AppDelegate.m
#import "AppDelegate.h"
#import "RootViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
RootViewController *rootViewController = [[RootViewController alloc] init];
rootViewController.title = @"首页";
return YES;
}
RootViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationController.navigationBar.translucent = NO;
//改变navigationBar颜色
self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 100, 50, 30);
button.backgroundColor = [UIColor orangeColor];
[button setTitle:@"push" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)buttonAction:(UIButton *)button{
SecondViewController *secondViewController = [[SecondViewController alloc] init];
//self.navigationController.navigationBarHidden = YES;
[self.navigationController pushViewController:secondViewController animated:YES];
}
SecondViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"<" style:UIBarButtonItemStylePlain target:self action:@selector(buttomAction:)];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(100, 200, 50, 30);
button1.backgroundColor = [UIColor greenColor];
[button1 setTitle:@"回来" forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(buttomAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}
-(void)buttomAction:(NSString *)button{
[self.navigationController popViewControllerAnimated:YES];
self.navigationController.navigationBarHidden = NO;
}