self.navigationController.navigationBar.barTintColor = [UIColor greenColor];字体
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];代理
attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];blog
attrs[NSFontAttributeName] = [UIFont systemFontOfSize:17];图片
[self.navigationController.navigationBar setTitleTextAttributes:attrs];get
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"left" style:UIBarButtonItemStylePlain target:self action:@selector(left)];it
self.navigationItem.leftBarButtonItem = leftItem;io
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"right" style:UIBarButtonItemStylePlain target:self action:@selector(right)]; table
self.navigationItem.rightBarButtonItem = rightItem;select
self.navigationController.navigationBar.tintColor = [UIColor redColor];若是要不一样item不一样颜色,那么item要带一个自定义按钮,在设置按钮属性scroll
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
self.navigationItem.backBarButtonItem = backItem;
self.view.backgroundColor = [UIColor greenColor];若是透明看到的就是绿色。而后在分别设置
[self.navigationController.navigationBar setBackgroundImage:[self imageWithBgColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0]] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[self imageWithBgColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0]]];这样就是透明的了
若是要监听滚动而使导航栏颜色渐变,那么能够在scrollView的代理方法中添加这样的代码
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self.navigationController.navigationBar setBackgroundImage:[self imageWithBgColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:self.tableView.contentOffset.y / 100]] forBarMetrics:UIBarMetricsDefault];
}
这边用的imageWithBgColor方法
-(UIImage *)imageWithBgColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
最后大体的效果点左边是默认颜色,点右边透明,滚动渐变,就在这记下这些了,但愿有能够帮助到的地方~~