iOS 導(dǎo)航欄顏色差異及下面有一條黑線

導(dǎo)航欄顏色差異:

設(shè)置導(dǎo)航欄的 translucent 屬性為 NO

在單個界面設(shè)置

self.navigationController.navigationBar.translucent = NO;

如果是導(dǎo)航欄單獨設(shè)置

 UINavigationBar * nav = [UINavigationBar appearance];
   //設(shè)置背景色
    nav.translucent = NO;
    nav.barTintColor = ColorPrimary;
 //設(shè)置字體顏色
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = White;
    [nav setTitleTextAttributes:textAttrs];
    [nav setTintColor:[UIColor whiteColor]];

對于導(dǎo)航欄和下面controller中間有一條線的情況,解決辦法是設(shè)置ShadowImage 屬性,但是這個屬性是設(shè)置那條線的顯示情況,單獨設(shè)置是不起作用的,只有同時設(shè)置 self.navigationController.navigationBar 的背景色才能起作用,所以這里設(shè)置self.navigationController.navigationBar 的背景色為空白圖片,并且把 ShadowImage設(shè)置為空白圖片 這樣就不會顯示出來那條黑線了,如果想把那條黑線改為其他顏色只需要修改 ShadowImage的圖片就可以了

對于單個界面

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
//兩句代碼必須都有
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"無圖片"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
}
-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
//兩句代碼必須都有
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"無圖片"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}

如果是全局設(shè)置(在UINavigationBar的封裝類里面設(shè)置就可以了)

//兩句代碼必須都要有
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"無圖片"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1、通過CocoaPods安裝項目名稱項目信息 AFNetworking網(wǎng)絡(luò)請求組件 FMDB本地數(shù)據(jù)庫組件 SD...
    陽明AI閱讀 16,213評論 3 119
  • 有位委屈女人被夫拋棄,找到一位據(jù)說常挽救婚姻的師母,要控訴丈夫。 師母問她:“你做了太太要做的嗎?”。 女人答:“...
    萬事從容閱讀 854評論 0 0
  • 這篇文章用了很久,從9月到11月底。因為我的強行拖延癥。 9月8日大學(xué)報到,開始了高考前報以無限遐想的...
    你說你單槍匹馬閱讀 414評論 4 0

友情鏈接更多精彩內(nèi)容