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];
//標(biāo)題
self.title = @"控制器標(biāo)題";
self.navigationItem.title = @"導(dǎo)航項(xiàng)標(biāo)題";
//自定義標(biāo)題視圖
// self.navigationItem.titleView = 自定義標(biāo)題視圖
//設(shè)置導(dǎo)航欄是否半透明 默認(rèn)YES
self.navigationController.navigationBar.translucent = YES;
//設(shè)置導(dǎo)航欄風(fēng)格
/**
* UIBarStyleDefault = 0,默認(rèn)白色
UIBarStyleBlack = 1,黑色
UIBarStyleBlackOpaque 同上
UIBarStyleBlackTranslucent = 2, 黑色半透明
*/
//設(shè)置導(dǎo)航欄是否隱藏 默認(rèn)NO
/**
* 設(shè)置為YES 則所有控制器都看不到導(dǎo)航欄,如果需要顯示 可以viewWillAppear中改為NO
*/
self.navigationController.navigationBarHidden = NO;
//設(shè)置導(dǎo)航欄item的字體顏色
self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
//設(shè)置導(dǎo)航欄顏色
self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
//設(shè)置導(dǎo)航欄背景顏色
self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
//設(shè)置導(dǎo)航欄背景圖片
/**
* UIBarMetricsLandscapePhone 橫屏
UIBarMetricsDefault 豎屏
*/
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_bg_normal"] forBarMetrics:UIBarMetricsDefault];
/*——————————————————定制導(dǎo)航欄按鈕————————————————————————————————————————————————————————————-*/
//1.系統(tǒng)樣式創(chuàng)建barbuttonitem
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(click:)];
//2.通過標(biāo)題創(chuàng)建
// UIBarButtonItem *leftItem2 = [[UIBarButtonItem alloc]initWithTitle:@"嘿嘿" style:UIBarButtonItemStyleBordered target:self action:@selector(click:)];
//3.通過圖片創(chuàng)建
// UIBarButtonItem *leftItem3 = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"refresh.png"] style:UIBarButtonItemStyleDone target:self action:@selector(click:)];
//4.通過自定義視圖創(chuàng)建
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
[button setImage:[UIImage imageNamed:@"write.png"] forState:UIControlStateNormal];
UIBarButtonItem *leftItem4 = [[UIBarButtonItem alloc]initWithCustomView:button];
//設(shè)置左側(cè)按鈕
self.navigationItem.leftBarButtonItem = leftItem;
//設(shè)置左側(cè)按鈕組
// self.navigationItem.leftBarButtonItems = @[leftItem,leftItem4];
//設(shè)置右側(cè)按鈕
self.navigationItem.rightBarButtonItem = leftItem4;
//設(shè)置右側(cè)按鈕組
// 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
屏幕快照 2016-03-09 下午8.08.24.png
效果圖
屏幕快照 2016-03-09 下午8.04.49.png