(转: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. php7 httpd 2.4 编译

    1.获取源码httpd-2.4.23.tar.gz   php-7.1.0.tar.gz,安装顺序必须是先安装http然后php,lnmp同理   2.安装编译环境和php.httpd依赖包,红色字体 ...

  2. asp TreeView控件的使用

    相对于之前发过一个TreeView控件的使用方法 本次利用js操作,页面无刷新,性能提高 Css编码可能时我的模板页样式被继承下来,导致页面变乱,不需要的可以去掉 前台 <style> . ...

  3. 20161117__安装Qt5.3.2

    1.strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX 2.yum install libGL-devel 2.在安装 Qt5.3.2x86的时候,会报错 ...

  4. java中的IO操作

    IO流是用来处理设备之间的数据传输,Java对数据的操作是通过流的方式进行,而操作流的对象都封装到java.io包中.根据操作数据的种类可以把IO流分为字节流(InputStream,OutputSt ...

  5. Bible

    001 Love your neighbor as yourself.         要爱人如己.--<旧·利>19:18      002 Resentment kills a foo ...

  6. 【WebGoat习题解析】Parameter Tampering->Bypass HTML Field Restrictions

    The form below uses HTML form field restrictions. In order to pass this lesson, submit the form with ...

  7. android adb常用命令

    android adb命令: adb root --获取root.adb remount --获取文件操作权限(push)adb shell pm list package 获取包名列表com.mqt ...

  8. HTTP 错误 500.23 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.NET 设置。

    检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为[经典]模式). - CatcherX 2014-03-11 11:03 27628人阅读 评论(2) 收藏 举报  分类 ...

  9. 即时反应的input和propertychange方法

    在web开发中,我们有时会需要动态监听输入框值的变化,当使用onkeydown.onkeypress.onkeyup作为监听事件时,会发现一些复制粘贴等操作用不了,同时,在处理组合快键键的时候也很麻烦 ...

  10. 使用script创建标签添加属性值和添加样式

    <mark>使用script创建标签和给标签属性值以及样式的方法</mark><script> window.onload=function(){ var btn= ...