自定义导航条上的标题文字的大小以及颜色

在做项目开发时,有的时候回自定义导航条视图,常见的是设置标题文字的大小颜色、左侧以及右侧navgationItem。

在做自定义导航视图的时候 ,导航项都可以用自定义视图的形式自定义。

自定义导航条标题的时候有两种方法:一是,采用自定义视图的方式;二是,采用系统的方法。

  • 采用自定义视图view的方式

         就是在导航向上添加一个titleView,可以使用一个label,再设置label的背景颜色透明,字体什么的设置就很简单了。                                                                    

          UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];                    

          titleLabel.backgroundColor = [UIColor grayColor];                                                                                                                              

          titleLabel.font = [UIFont boldSystemFontOfSize:20];

          titleLabel.textColor = [UIColor  greencolor];  

          titleLabel.textAlignment = NSTextAlignmentCenter;                                                                                                                                                                                                           

          titleLabel.text = @"新闻";                                                                                                                                    

          self.navigationItem.titleView = titleLabel;

  • 在默认显示的标题中直接修改文件的大小和颜色也是可以的

 

      //设置标题的大小以及标题文字的颜色

 

             [self.navigationController.navigationBar setTitleTextAttributes:

                   @{NSFontAttributeName:[UIFont systemFontOfSize:20], //设置导航条标题文字的大小

                    NSForegroundColorAttributeName:[UIColor whiteColor]}];//设置导航条标题文字的颜色

 

posted @ 2016-08-01 14:57  寂寞的倔强  Views(665)  Comments(0Edit  收藏  举报