在导航栏中创建一个副标题

时间:2015-04-14 11:58:50

标签: objective-c uinavigationbar

在iOS中,您可以使用以下内容创建标题:

self.navBar.title = @"";

我在头文件中设置了navBar。

是否还有subTitle / Description的内容?

我在description后输入.后发现self.navBar,我想也许我可以对此做些什么?

2 个答案:

答案 0 :(得分:6)

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

来自UIKit的基础UINavigationViewController。

答案 1 :(得分:0)

solution

的Objective-C代码
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;