码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-08-01 15:44:30      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

在做项目开发时,有的时候回自定义导航条视图,常见的是设置标题文字的大小颜色、左侧以及右侧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]}];//设置导航条标题文字的颜色

 

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

标签:

原文地址:http://www.cnblogs.com/liu-lang/p/5725860.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!