iOS中设置导航栏标题( titleView)的字体颜色和大小
2016-03-02 14:53
696 查看
在iOS中,经常会对一些导航栏titleView进行自定义,首先介绍一下对navgationBar 上的title设置的三种方法:
<1> self.title = @"我是title" ;
直接设置
<2> self.navigationItem.title = @"我是title" ;
以上两种方法 title的显示跟调用顺序有关,谁后调用显示谁
<3> UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 62, 20)] ;
titleLabel.text = @"我是title" ;
self.navigationItem.titleView = titleLabel ;
以上<3>的显示优先级是最高的 其实是<1><2>,<1><2>相互没有优先级,只跟调用顺序有关
对于titleView的字体颜色和大小 我们主要是针对于上面第三种方法进行两种方式的设置:
<1> UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 62, 20)] ;
titleLabel.text = @"我是title" ;
titleLabel.backgroundColor = [UIColor blueColor] ;
titleLabel.textColor = [UIColor whiteColor] ;
titleLabel.font = [UIFont systemFontOfSize:26] ;
self.navigationItem.titleView = titleLabel ;
<2> [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:26],NSForegroundColorAttributeName:[UIColor whiteColor]}] ;
<1> self.title = @"我是title" ;
直接设置
<2> self.navigationItem.title = @"我是title" ;
以上两种方法 title的显示跟调用顺序有关,谁后调用显示谁
<3> UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 62, 20)] ;
titleLabel.text = @"我是title" ;
self.navigationItem.titleView = titleLabel ;
以上<3>的显示优先级是最高的 其实是<1><2>,<1><2>相互没有优先级,只跟调用顺序有关
对于titleView的字体颜色和大小 我们主要是针对于上面第三种方法进行两种方式的设置:
<1> UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 62, 20)] ;
titleLabel.text = @"我是title" ;
titleLabel.backgroundColor = [UIColor blueColor] ;
titleLabel.textColor = [UIColor whiteColor] ;
titleLabel.font = [UIFont systemFontOfSize:26] ;
self.navigationItem.titleView = titleLabel ;
<2> [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:26],NSForegroundColorAttributeName:[UIColor whiteColor]}] ;
相关文章推荐
- 通过 itms-services 协议,发布或者分享 iOS 应用程序
- iOS-定时任务
- iOS-此证书的签发者无效
- iOS绘制专属于程序猿的浪漫爱心
- IOS开发学习之自定义XIB的使用
- iOS 3D touch的实现 从零开始
- iOS
- IOS--静态多线程
- iOS开发通过代码方式使用AutoLayout (NSLayoutConstraint + Masonry)
- iOS开发技巧:获取手机应用程序图片素材
- IOS开发基础知识--碎片35
- iOS开发之封装水平菜单栏
- ios版本更新
- [iOS]细说OC中的load和initialize方法
- 获取iOS设备信息
- IOS 无法解析 报错std::basic_string/std::string::find
- iOS 中 set,get方法
- iOS 中单例写法
- iOS 成员变量跟属性的区别
- 【iOS】使用Xib自定义tableViewCell 获取数据