UINavigationController的一些小用法

項目開發(fā)中UINavigationController非常常用,各種設(shè)置也是非常普遍,此文收納一些方法,一些曾經(jīng)讓自己迷茫過的問題,記錄下解決方法,以待以后優(yōu)化。

怎么設(shè)置UINavigationController透明化

  • 方法一
-(void)setNavigationBarType
{
    self.navigationController.navigationBar.translucent=YES;
    UIColor *color=[UIColor clearColor];
    CGRect rect=CGRectMake(0, 0, WIDTH, 64);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context=UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.clipsToBounds=YES;
}

  • 方法二
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  • 方法三
[self.navigationController setNavigationBarHidden:YES];
  • 方法四
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
 [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
//下面代碼
![Uploading CF061DA9-BF86-422C-9B95-6A4005AFA06E_661264.png . . .]取消透明效果
 [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];

設(shè)置NavigationBar的背景顏色

[nv.navigationBar setBarTintColor:[UIColor yellowColor]];
E0289EDE-7567-415B-95DF-E9BCF4F5163D.png

設(shè)置標(biāo)題顏色

[nv.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName,nil]];
A39977EC-EFB0-4BA6-AD28-6BF71102B39D.png

設(shè)置rightBarButtonItem顏色

    [self.navigationController.navigationBar setTintColor:[UIColor greenColor]];
CF061DA9-BF86-422C-9B95-6A4005AFA06E.png

借鑒:UINavigationBar 使用總結(jié)

最后編輯于
?著作權(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)容

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