iOS中设置导航栏标题( titleView)的字体颜色和大小

来源:互联网 发布:淘宝关键词点击率查询 编辑:程序博客网 时间:2024/05/02 04:44

在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 1
原创粉丝点击