IOS-43-导航栏标题navigationItem.title不能改变颜色的两种解决方法

IOS-43-导航栏标题navigationItem.title不能改变颜色的两种解决方法

两种方法只是形式不一样而已,但是第一种适合在导航栏特别多,而且只需要在被统一继承的基类里面设置即可:

1.在本类或者所继承的基类重写此方法:

- (void)setTitle:(NSString *)title;

见代码:

// 重写set title方法

- (void)setTitle:(NSString *)title {

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

titleLabel.text             = title;

titleLabel.font             = [UIFont boldSystemFontOfSize:20.f];

titleLabel.textAlignment    = NSTextAlignmentCenter;

titleLabel.textColor        = [UIColor whiteColor];

self.navigationItem.titleView = titleLabel;

}

2.第二种就是直接在viewWillAppear:(BOOL)animated方法

见代码:

-(void)viewWillAppear:(BOOL)animated{

[super viewWillAppear:animated];

UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];

titleLabel.text             = @"换肤";

titleLabel.font             = [UIFont boldSystemFontOfSize:20.f];

titleLabel.textAlignment    = NSTextAlignmentCenter;

titleLabel.textColor        = [UIColor whiteColor];

self.navigationItem.titleView = titleLab;

}

IOS-43-导航栏标题navigationItem.title不能改变颜色的两种解决方法的更多相关文章

  1. ios7以上自定义导航栏标题的字体大小及颜色的方法

    自定义导航栏的字体和颜色,只需要自定义一个lable,然后将lable添加到导航栏的titleview中就可以了 代码如下 UILabel *label = [[UILabel alloc] init ...

  2. iOS设置导航栏标题

    方法一:在UIViewController中设置self.title. 方法二:设置self.navigationItem.titleView.

  3. 【转】iOS中设置导航栏标题的字体颜色和大小

    原文网址:http://www.360doc.com/content/15/0417/11/20919452_463847404.shtml iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参 ...

  4. iOS中设置导航栏标题的字体颜色和大小

    iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参考下. 在平时开发项目的时候,难免会遇到修改导航栏字体大小和颜色的需求,一般使用自定义视图的方法,其实还存在一种方法. 方法一:(自定义视图的 ...

  5. iOS 11 导航栏 item 偏移问题 和 Swift 下 UIButton 设置 title、image 显示问题

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

  6. 【转】【iOS】导航栏那些事儿

    原文网址:http://www.jianshu.com/p/f797793d683f 参考文章 navigationItem UINavigationItem UINavigationBar UIBa ...

  7. uni-app动态修改顶部导航栏标题

    动态修改顶部导航栏标题有两种方法方式一.使用自定义到导航栏,覆盖原生导航栏 缺点:自定义到导航栏性能远远不如原生导航栏,手机顶部状态栏区域会被页面内容覆盖,这是因为窗体是沉浸式的原因,即全屏可写内容: ...

  8. iOS设置导航栏样式(UINavigationController)

    //设置导航栏baritem和返回baiitem样式 UIBarButtonItem *barItem = [UIBarButtonItem appearance]; //去掉返回按钮上的字 [bar ...

  9. 设置导航栏 self.navigationItem.titleView 居中

    喜欢交朋友的加:微信号 dwjluck2013-(void)viewDidLayoutSubviews{ [self setDisplayCustomTitleText:@"每日头条&quo ...

随机推荐

  1. python轻量级数据存储

    python为开发者提供了一个轻量级的数据存储方式shelve,对于一些轻量数据,使用shelve是个比较不错的方式.对于shelve,可以看成是一个字典,它将数据以文件的形式存在本地.下面介绍具体用 ...

  2. 思科4506E做ehterchannel故障排查

    思科4506E做ehterchannel故障排查 转载于:https://blog.51cto.com/eric1026/1910912 一.故障描述 某客户有两台4506E汇聚交换机,需要做ethe ...

  3. 好系统重装助手教你如何让win10系统快速开机

    电脑开机的时候,有一些自动开启的软件或工具会占用一定的开机时间,把它们禁止开机启动项就会提高电脑开机速度.很多人会借助360或者电脑管家等软件来设置,下面小编就来教大家一招不借助第三方工具来禁止win ...

  4. Linux下完全删除用户

    实验环境:Centos7虚拟机 首先创建一个普通用户gubeiqing. [root@localhost ~]# useradd gubeiqing [root@localhost ~]# passw ...

  5. March 05th, 2018 Week 10th Monday

    Fortune favors the bold. 勇者天佑. It has been increasingly apparent that courage is the main quality we ...

  6. ABAP 7.50 新特性 – Open SQL中的宿主表达式和其它表达式

    在长期的停滞后,Open SQL的发展终于从沉睡中醒来.从ABAP 7.40开始,SAP推进了某些关键的改变,以尽可能地包含SQL92中的特性,并提供与ABAP CDS中的DDL里面的SELECT一样 ...

  7. C#基础知识之读取xlsx文件Excel2007

    读取Excel 2007的xlsx文件和读取老的.xls文件是一样的,都是用Oledb读取,仅仅连接字符串不同而已. 具体代码实例: public static DataTable GetExcelT ...

  8. C# 基础知识之 Unix 时间戳转换

    unix时间戳是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒. /// 时间戳转为C#格式时间 private DateTime GetTime(string timeSt ...

  9. chrome的source工具

    http://www.cnblogs.com/ys-ys/p/5597717.html http://www.cnblogs.com/strick/p/5556434.html

  10. 一、tars简单介绍 二、tars 安装部署资料准备

    1.github地址https://github.com/Tencent/Tars/ 2.tars是RPC开发框架,目前支持c++,java,nodejs,php 3.tars 在腾讯内部已经使用了快 ...