您的位置:首页 > 移动开发 > IOS开发

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]}] ;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: