(转: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. JQ_浏览器窗口改变触发

    $(window).resize(function () { //当浏览器大小变化时 alert($(window).height()); //浏览器时下窗口可视区域高度 alert($(docume ...

  2. contiki-事件调度

    事件驱动机制广泛应用于嵌入式系统,类似于中断机制,当有事件到来时(比如按键.数据到达),系统响应并处理该事件.相对于轮询机制,事件机制优势很明星,低功耗(系统处于休眠状态,当有事件到达时才被唤醒)和M ...

  3. Docker实践,来自沪江、滴滴、蘑菇街架构师的交流分享

    架构师小组交流会:每期选一个时下最热门的技术话题进行实践经验分享. 第一期主题:容器实践.Docker 作为当前最具颠覆性的开源技术之一,其轻量虚拟化.可移植性是CI/CD,DevOps,微服务的重要 ...

  4. js递归方法创建节点

    var jsonData = [{,,"subnetRemark":"状态自带","subnetName":"中心网络" ...

  5. js点击按钮div显示,点击div或者body和按钮,div隐藏

    var box = document.getElementById("box"); var btn = document.getElementById("btn" ...

  6. 即时聊天IM之四 Android客户端IM帮助类编写

    图文无关一起娱乐: 这一篇我们开始写Android端的Smack版主类,后面Android的IM功能都是通过这个帮助类实现的 引用类库: 因为我用的是IDE是Android Studio,所以我通过g ...

  7. Windows 10系统更换Windows 7系统磁盘分区注意事项一

    新买的电脑预装系统是WIN10,考虑到兼容性问题,打算更换为WIN7,但在新机上不能直接装WIN7系统,需要在BIOS启动中做一点小改动. 原因分析:由于Windows 8采用的是UEFI引导和GPT ...

  8. Transport Block Size, Throughput and Code rate-----http://www.simpletechpost.com/2012/12/transport-block-size-code-rate-protocol.html

    Transport Block Size, Throughput and Code rate   Since the size of transport block is not fixed, oft ...

  9. 分治法解决合并排序(c++和Java源代码)

    Java源代码 public class Mergesort1 { public static void merge(int[]a,int low,int mid,int high){//对两组已经排 ...

  10. [高斯消元] POJ 2345 Central heating

    Central heating Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 614   Accepted: 286 Des ...