项目开发中UINavigationController非常常用,各种设置也是非常普遍,此文收纳一些方法,一些曾经让自己迷茫过的问题,记录下解决方法,以待以后优化。
怎么设置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];
设置NavigationBar的背景颜色
[nv.navigationBar setBarTintColor:[UIColor yellowColor]];
设置标题颜色
[nv.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName,nil]];
设置rightBarButtonItem颜色
[self.navigationController.navigationBar setTintColor:[UIColor greenColor]];