IOS导航栏颜色渐变与常用属性
来源:互联网 发布:网络电影发行流程 编辑:程序博客网 时间:2024/05/21 10:29
- 导航栏标题颜色字体大小
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
attrs[NSFontAttributeName] = [UIFont systemFontOfSize:17];
[self.navigationController.navigationBar setTitleTextAttributes:attrs];
- 导航栏左右item
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"left" style:UIBarButtonItemStylePlain target:self action:@selector(left)];
self.navigationItem.leftBarButtonItem = leftItem;
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"right" style:UIBarButtonItemStylePlain target:self action:@selector(right)];
self.navigationItem.rightBarButtonItem = rightItem;
- 导航栏item字体颜色
self.navigationController.navigationBar.tintColor = [UIColor redColor];如果要不同item不同颜色,那么item要带一个自定义按钮,在设置按钮属性
- 当前控制器的下一个控制的返回item去掉文字只保留箭头
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
self.navigationItem.backBarButtonItem = backItem;
- 导航栏透明与导航栏底部分割线,如果有图片高为64的话,直接设置图片就可以了,除此之外还可以用代码,这边的例子全部用代码背景色转图片来设置,先设置整个view的背景色为
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;
}
- 导航栏标题颜色字体大小
- iOS 导航栏颜色渐变与常用属性
- IOS导航栏颜色渐变与常用属性
- iOS导航栏颜色渐变与常用属性
- IOS导航栏颜色渐变与常用属性
- IOS导航栏颜色渐变与常用属性(最近应用比较流行的风格)
- iOS 导航栏颜色渐变
- iOS 导航栏标题文字颜色渐变
- iOS设置导航栏渐变颜色
- 简易的iOS导航栏颜色渐变方案
- 导航栏颜色渐变效果
- iOS 导航栏渐变
- iOS - 导航栏UINavigationController常用属性
- iOS开发导航栏常用属性
- iOS 10导航栏常用属性设置
- ios--导航控制器常用属性与常用方法
- iOS导航控制器常用函数与navigationBar常用属性
- iOS导航控制器常用函数与navigationBar常用属性
- 设置导航栏颜色渐变的效果
- Memcached 及 Redis 架构分析和比较(一)
- PL/SQL基础1
- redis memcached比较
- netstat命令
- angularJS学习之路(十一)---ng-show和ng-hide
- IOS导航栏颜色渐变与常用属性
- 【iOS】关于视图的旋转和复原(CGAffineTransform)
- 改变导航的返回按钮
- poj 1734 Sightseeing trip (floyd求最小环并记录路径)
- photoshop将多个图片合成制作gif
- 用数组实现队列(C实现)
- 每天学习一算法系列(6) (输入一个整数和一棵二元树,从树的根结点开始往下访问一直到叶结点所经过的所有结点形成一条路径,打印出和与输入整数相等的所有路径)
- 项目及人员管理
- Linux下创建shell命令集合——你意想不到的软连接