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;
}
最後大體的效果點左邊是默認顏色,點右邊透明,滾動漸變,就在這記下這些了,但願有能夠幫助到的地方~~