UINavigationController 總結

一 . UINavigationBarapp

  1.獲取 UINavigationBar 對象: [UINavigationBar appearance] ,能夠經過該方法對所有 navigation 進行設置字體

  2.設置導航欄背景圖片:[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"name"] forBarMetrics:UIBarMetricsDefault];spa

  3.設置標題字體:[UINavigationBar appearance].titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};code

二 . UIBarButtonItemorm

  1.獲取 UIBarButtonItem 對象: [UIBarButtonItem appearance] 能夠經過該方法實現對 barButtonItem (即導航欄按鈕)樣式,顯示字體進行設置 (同一 navigation 下所有)對象

  2.設置按鈕的顏色,大小 : [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:13]} forState:UIControlStateNormal];圖片

  3.設置導航欄漸變色(返回箭頭白色) : [UIBarButtonItem appearance].tintColor = [UIColor whiteColor];it

三 . 去除 navigation 下邊黑線io

//去掉導航欄黑線
    [[UINavigationBar appearance]  setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];

四 . 修改 backItem 爲圖片class

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[[UIImage imageNamed:@"common_nav_back"] imageWithAlignmentRectInsets:UIEdgeInsetsMake(0, 0, 0, -15)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];

圖片進行處理,不然圖片會被橫向拉伸(imageWithAlignmentRectInsets 設置圖片距離邊的距離)

五 . 用本身的圖片替換V型,能夠設置圖片的backIndicatorImagebackIndicatorTransitionMaskImage。以下代碼所示:

[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"back_btn.png"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back_btn.png"]];
相關文章
相關標籤/搜索