AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "ABCViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
/*——————————————————————————————————————————————————————————————————————————————-*/
ABCViewController *abc = [[ABCViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:abc];
self.window.rootViewController = nav;
return YES;
}
@end
ABCViewController.m
#import "ABCViewController.h"
@interface ABCViewController ()
@end
@implementation ABCViewController
- (void)viewDidLoad {
[super viewDidLoad];
//标题
self.title = @"控制器标题";
self.navigationItem.title = @"导航项标题";
//自定义标题视图
// self.navigationItem.titleView = 自定义标题视图
//设置导航栏是否半透明 默认YES
self.navigationController.navigationBar.translucent = YES;
//设置导航栏风格
/**
* UIBarStyleDefault = 0,默认白色
UIBarStyleBlack = 1,黑色
UIBarStyleBlackOpaque 同上
UIBarStyleBlackTranslucent = 2, 黑色半透明
*/
//设置导航栏是否隐藏 默认NO
/**
* 设置为YES 则所有控制器都看不到导航栏,如果需要显示 可以viewWillAppear中改为NO
*/
self.navigationController.navigationBarHidden = NO;
//设置导航栏item的字体颜色
self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
//设置导航栏颜色
self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
//设置导航栏背景颜色
self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
//设置导航栏背景图片
/**
* UIBarMetricsLandscapePhone 横屏
UIBarMetricsDefault 竖屏
*/
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_bg_normal"] forBarMetrics:UIBarMetricsDefault];
/*——————————————————定制导航栏按钮————————————————————————————————————————————————————————————-*/
//1.系统样式创建barbuttonitem
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(click:)];
//2.通过标题创建
// UIBarButtonItem *leftItem2 = [[UIBarButtonItem alloc]initWithTitle:@"嘿嘿" style:UIBarButtonItemStyleBordered target:self action:@selector(click:)];
//3.通过图片创建
// UIBarButtonItem *leftItem3 = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"refresh.png"] style:UIBarButtonItemStyleDone target:self action:@selector(click:)];
//4.通过自定义视图创建
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
[button setImage:[UIImage imageNamed:@"write.png"] forState:UIControlStateNormal];
UIBarButtonItem *leftItem4 = [[UIBarButtonItem alloc]initWithCustomView:button];
//设置左侧按钮
self.navigationItem.leftBarButtonItem = leftItem;
//设置左侧按钮组
// self.navigationItem.leftBarButtonItems = @[leftItem,leftItem4];
//设置右侧按钮
self.navigationItem.rightBarButtonItem = leftItem4;
//设置右侧按钮组
// self.navigationItem.rightBarButtonItems = @[leftItem,leftItem4];
}
- (void)click:(UIBarButtonItem *)item{
}
- (IBAction)push:(UIButton *)sender {
ABCViewController *vc = [[ABCViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
@end
ABCViewController.xib
效果图