导航栏设置
//设置导航栏颜色方法1 --- 全局
UINavigationBar *navigationBar = [UINavigationBar appearance];
[navigationBar setBarTintColor:[UIColor redColor]];
//设置导航栏颜色方法2 --- 当前控制器
[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
// 设置导航栏栏的背景图片
[self.navigationBar setBackgroundImage:[UIImage imageNamed:@"NavBar64"] forBarMetrics:UIBarMetricsDefault];
// 设置导航栏的文字外观
NSDictionary *dict = @{
NSFontAttributeName:[UIFont systemFontOfSize:16],
NSForegroundColorAttributeName:[UIColor whiteColor]
};
[self.navigationBar setTitleTextAttributes:dict];
//设置导航栏上的item外观
[self.navigationBar setTintColor:[UIColor whiteColor]];
//导航栏自定义按钮设置
UIBarButtonItem * rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"账单" style: UIBarButtonItemStylePlain target:self action:@selector(menuBtnAction)];
[rightBtn setTintColor:[UIColor blackColor]];//设置颜色
self.navigationItem.rightBarButtonItem = rightBtn;
//navigationBar 留空白问题
self.automaticallyAdjustsScrollViewInsets = NO;// 自动滚动调整,默认为YES
self.navigationController.navigationBar.translucent = NO;// Bar的模糊效果,默认为开启
self.edgesForExtendedLayout = UIRectEdgeNone;// iOS7及以后的版本支持,self.view.frame.origin.y会下移64像素至navigationBar下方。
自定义导航栏
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width,44)];
navigationBar.translucent = NO;
navigationBar.barTintColor = [DWHColorFromRGB(0xf9f9f9) colorWithAlphaComponent:1];
extern UIImage *navigationShadeImage;
[navigationBar setShadowImage:navigationShadeImage];
UINavigationItem *navigationItem = [[UINavigationItem alloc] init];
UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[leftBtn setImage:[UIImage imageNamed:@"common_back"] forState:UIControlStateNormal];
__weak typeof(self) weakSelf = self;
[[leftBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
[weakSelf dismissViewControllerAnimated:YES completion:nil];
}];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
navigationItem.leftBarButtonItem = leftItem;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont systemFontOfSize:19];
label.text = @"粉丝贡献榜";
label.textColor = DWHColorFromRGB(0x333333);
navigationItem.titleView = label;
[navigationBar setItems:[NSArray arrayWithObject:navigationItem]];
[self.view addSubview:navigationBar];