(转:http://www.cnblogs.com/Lingchen-start/archive/2015/10/23/4904361.html)

今年很忙,忙的写日志的时间都很少。  少的可怜。

自己一直想实现导航栏的几个功能,

  1、去掉导航栏中的下划线

2、导航栏透明度,背景色随着Scroll 滚动而改变

又是偶然间的发现以下博客;满足了自己的想法

    • 1、导航栏背景色设置:

      self.navigationController.navigationBar.barTintColor = [UIColor greenColor];

    • 2、导航栏标题颜色字体大小

      NSMutableDictionary *attrs = [NSMutableDictionary dictionary];

      attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];

      attrs[NSFontAttributeName] = [UIFont systemFontOfSize:17];

      [self.navigationController.navigationBar setTitleTextAttributes:attrs];

    • 3、导航栏左右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;

    • 4、导航栏item字体颜色

      self.navigationController.navigationBar.tintColor = [UIColor redColor];如果要不同item不同颜色,那么item要带一个自定义按钮,在设置按钮属性

    • 5、当前控制器的下一个控制器的返回item去掉文字只保留箭头

      UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(back)];

      self.navigationItem.backBarButtonItem = backItem;

    • 6、导航栏透明与导航栏底部分割线,如果有图片高为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]]];这样就是透明的了

    • 7、如果要监听滚动而使导航栏颜色渐变,那么可以在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导航栏颜色渐变与常用属性的更多相关文章

  1. IOS 导航栏颜色 标题

    修改导航栏颜 #define COLOR_TOMATO    [UIColor colorWithRed:255/255.0f green:99/255.0f blue:71/255.0f alpha ...

  2. iOS 导航栏颜色字体等的自定义

    1.设置导航栏中间文字的文字颜色和文字大小 方法一:系统方法 self.title = @"下载微课";//在有navigationController的控制器中,作用与self. ...

  3. 几句话实现导航栏透明渐变 – iOS

    首先我们来看下效果 一开始当我们什么只设置了一张图片作为它的头部视图的时候,它是这样的 首当其冲的,我们先得把导航栏弄透明 那么我们首先得知道,设置navigationBar的BackgroundCo ...

  4. swift 自定义导航栏颜色

    func setNavigationApperance(){ //自定义导航栏颜色 [self.navigationController?.navigationBar.barTintColor = U ...

  5. 设置全局导航栏颜色,标题大小和UIBarButtonItem字体大小

    设置全局导航栏颜色,标题大小和UIBarButtonItem字体大小 在appdelegate里面设置 swift: UINavigationBar.appearance().barTintColor ...

  6. IOS 导航栏属性设置

    IOS 7 以上系统导航栏: [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; // 返回按钮颜色 [UINaviga ...

  7. iOS导航栏背景,标题和返回按钮文字颜色

    在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...

  8. iOS 更改状态栏、导航栏颜色的几种方法

    ios上状态栏 就是指的最上面的20像素高的部分状态栏分前后两部分,要分清这两个概念,后面会用到: 前景部分:就是指的显示电池.时间等部分:背景部分:就是显示黑色或者图片的背景部分: (一)设置sta ...

  9. iOS导航栏NavigationBar的颜色,按钮和标题以及字体颜色

    首先,层级关系: leftBarButtonItem.rightBarButtonItem.title都是加在UINavigationItem上的,UINavigationItem再加在Navigat ...

随机推荐

  1. Jquery实现账单全部选中和部分选中管理

    在做购物车系统是我们往往会遇到这样一个需求,在点击全选框时我们要将全部的单个账单都选中;在单个选中账单时,如果账单全部被选中则需要全选框处于选中状态,若没有全部被选中则全选框处于没选中状态; 以下是在 ...

  2. testlink部署与迁移

    几个特殊的文件: 1.D:\xampp\htdocs\testlink\config.inc  安装配置文件,此处需要修改安装目录(g_repositoryPath.log_path) 2.D:\xa ...

  3. Sprint1(第四天11.17)

    Sprint1第一阶段 1.类名:软件工程-第一阶段 2.时间:11.14-11.23 3.选题内容:web版-餐厅到店点餐系统 4.团队博客地址: http://www.cnblogs.com/qu ...

  4. css3 rem的用法

    rem这是个低调的css单位,近一两年开始崭露头角,有许多同学对rem的评价不一,有的在尝试使用,有的在使用过程中遇到坑就弃用了.但是我对rem综合评价是用来做web app它绝对是最合适的人选之一. ...

  5. mysql 重置root密码

    最近又项目用到mysql 由于电脑上mysql是很久以前安装的root密码忘记了, 百度一下重置密码 Windows: 1.以系统管理员登陆: 2.停止MySQL服务: 3.进入CMD,进入MySQL ...

  6. document.all.wb.ExecWB

      <%@ page language="java" pageEncoding="UTF-8"%>   <%@ taglib uri=&quo ...

  7. CSS3支持box-flex弹性布局

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...

  8. YY前端课程3

    1. 常用的字符实体(html实体):空格=      <=<       >=>       版权符号=© 2. ID就像身份证号一样,是唯一的,html页面的ID不能重复: ...

  9. 配置 Windows 下的 nodejs C++ 模块编译环境

    根据 node-gyp 指示的 Windows 编译环境说明, 简单一句话就是 "Python + VC++ 编译环境". 所有需要的安装文件, 我都下载好放到百度云盘了: nod ...

  10. C#中获取当前时间:System.DateTime.Now.ToString()用法

    //2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.ToString(& ...