Day.03.09 導(dǎo)航欄

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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 1.尺寸適配1.原因 iOS7中所有導(dǎo)航欄都為半透明,導(dǎo)航欄(height=44)和狀態(tài)欄(height=20)不...
    LZM輪回閱讀 6,137評(píng)論 1 4
  • 1,NSObject中description屬性的意義,它可以重寫嗎?答案:每當(dāng) NSLog(@"")函數(shù)中出現(xiàn) ...
    eightzg閱讀 4,179評(píng)論 2 19
  • 今天是你的生日? 可能吧,我也不確定 我說,生日快樂 一整天了,都沒有回應(yīng) 懷念那個(gè)野草蔓歌的年代 所有情緒都可以...
    宋小溫閱讀 225評(píng)論 7 2
  • 碧海藍(lán)天,晴空萬里,白云朵朵。 那年高考后,一因同學(xué)在煙臺(tái),二因想去海邊。就來到煙臺(tái),開始四年大學(xué)生活。 記得那年...
    神之巫師閱讀 486評(píng)論 0 0
  • 問:為什么在超市排隊(duì),我選的隊(duì)伍總是最慢的? 答:大多數(shù)時(shí)候不是你真的運(yùn)氣不佳,只不過是你總對(duì)倒霉的事情印象深刻。...
    港兒i閱讀 143評(píng)論 0 0