导航栏添加子标题

来源:互联网 发布:广州本科网络教育 编辑:程序博客网 时间:2024/06/07 06:31



//声明两个label

@property(nonatomic,strong)UILabel *naTitle;

@property(nonatomic,strong)UILabel *naSubTitle;



- (void)creatNav{

  

    UIView *la = [[UIViewalloc]init];

    la.frame =CGRectMake(0,20, [UIScreenmainScreen].bounds.size.width,44);

    

    self.naTitle = [[UILabelalloc]init];

    self.naTitle.frame =CGRectMake(150/2,2, [UIScreenmainScreen].bounds.size.width-150.0f,23.0f);

    self.naTitle.textColor =[UIColorwhiteColor];

    self.naTitle.textAlignment = NSTextAlignmentCenter;

    self.naTitle.font = [UIFont systemFontOfSize:20];

    //    navTitleL.backgroundColor =[UIColor redColor];

    [la addSubview:self.naTitle];

    

    self.naSubTitle = [[UILabelalloc]init];

    self.naSubTitle.frame =CGRectMake(150/2,23,[UIScreenmainScreen].bounds.size.width-150.0f,17.0f);

    self.naSubTitle.textColor =[UIColorwhiteColor];

    self.naSubTitle.textAlignment = NSTextAlignmentCenter;

    self.naSubTitle.font =[UIFont systemFontOfSize:14];

    [la addSubview:  self.naSubTitle];

    

//视图替换

    self.navigationItem.titleView =   la;

    

    self.naSubTitle.text  =@"主标题";

    self.naTitle.text  =@"副标题";

    self.naSubTitle.textColor=[UIColorblackColor];

    self.naTitle.textColor =[UIColorredColor];

    

    

}


  调用;


 [selfcreatNav];





原创粉丝点击