5

In iOS you can create a title with:

self.navBar.title = @"";

where I set navBar in the header file.

Is there also something for the subTitle / Description?

I found description when I typed a . after self.navBar and thought maybe I could do something with this?

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
ComputerFreak
  • 87
  • 1
  • 9

2 Answers2

7

Use the self.navBar.navigationItem.prompt = @"This is the subtitle";

It's from UIKit in the base UINavigationViewController.

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
0

Objective-C code for the solution

UILable *title = [[UILabel alloc]init];
UILabel *subtitle = [[UILabel alloc]init];

[title setFont:[UIFont systemFontOfSize:12]];
[title setTextColor:[UIColor whiteColor]];
[title setFont:[UIFont systemFontOfSize:17]];
[title sizeToFit];
title.text = @"Title";

[subtitle setTextColor:[UIColor whiteColor]];
[subtitle setFont:[UIFont systemFontOfSize:12]];
[subtitle setTextAlignment:NSTextAlignmentCenter];
[subtitle sizeToFit];
subtitle.text = @"Subtitle Title";

UIStackView *stackVw = [[UIStackView alloc]initWithArrangedSubviews:@[title,subtitle]];
stackVw.distribution = UIStackViewDistributionEqualCentering;
stackVw.axis = UILayoutConstraintAxisVertical;
stackVw.alignment =UIStackViewAlignmentCenter;


[stackVw setFrame:CGRectMake(0, 0, MAX(title.frame.size.width, subtitle.frame.size.width), 35)];
self.navigationItem.titleView = stackVw;
Mubeen Qazi
  • 167
  • 1
  • 8