gpt4 book ai didi

ios - 在导航栏中显示大量信息

转载 作者:行者123 更新时间:2023-11-29 01:34:49 24 4
gpt4 key购买 nike

我正在使用 Swift 1.2 和 Xcode 6.4 开发一个项目。

我已经到了想要完全自定义导航栏的地步。主要目标是显示一些会不断变化的用户数据。为此,我需要有一个更大的导航栏,我可以在其中添加至少 6 个标签。

Navigation bar

我想知道这是否可行,以及如何实现?谢谢

最佳答案

我相信通过添加多个字幕标签,这段代码应该很容易适应。您可以像这样向导航栏添加自定义标题 View :

Result Image

- (void)updateTitle
{
if(self.hasAppeared) {
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 180, 44)];

UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
titleLabel.text = convo[@"name"];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = [UIColor whiteColor];
titleLabel.font = [UIFont fontWithName:@"Quicksand-Light" size:18];
titleLabel.adjustsFontSizeToFitWidth = YES;
titleLabel.minimumScaleFactor = 0.7;
[titleView addSubview:titleLabel];

UILabel *subtitleLabel = [[UILabel alloc] init];
subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
subtitleLabel.text = self.otherPersonString;
subtitleLabel.textAlignment = NSTextAlignmentCenter;
subtitleLabel.textColor = [UIColor whiteColor];
subtitleLabel.font = [UIFont fontWithName:@"Quicksand-Light" size:13];
subtitleLabel.adjustsFontSizeToFitWidth = YES;
subtitleLabel.minimumScaleFactor = 0.7;
[titleView addSubview:subtitleLabel];

NSDictionary *views = NSDictionaryOfVariableBindings(titleLabel, subtitleLabel);

[titleView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[titleLabel]-|" options:0 metrics:nil views:views]];
[titleView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[subtitleLabel]-|" options:0 metrics:nil views:views]];
[titleView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(-3)-[titleLabel]-(-2)-[subtitleLabel]-(1)-|" options:0 metrics:nil views:views]];

self.navigationItem.titleView = titleView;
}
}

但是,您将无法更改导航栏本身的高度,除非您重新创建该内容,否则该内容不会在整个应用程序中始终保留在导航栏中。您有什么理由不能将它添加到导航栏下方的新 View 中?

关于ios - 在导航栏中显示大量信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33084213/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com