问题
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?
回答1:
Use the self.navBar.navigationItem.prompt = @"This is the subtitle";
It's from UIKit in the base UINavigationViewController.
回答2:
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;
来源:https://stackoverflow.com/questions/29626710/create-a-subtitle-in-navigationbar