gpt4 book ai didi

ios - 如何读取UINavigationController中标题的字体?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:41 24 4
gpt4 key购买 nike

如何获取UINavigationController中标题的UIFont?我试图像这样阅读它:

- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Some text here";
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"navigation bar title attributes = %@", self.navigationController.navigationBar.titleTextAttributes);
NSLog(@"title font = %@", [self.navigationController.navigationBar.titleTextAttributes objectForKey:UITextAttributeFont]);
}

结果令人失望。 titleTextAttributes 字典只包含一个键/值,不是字体。

navigation bar title attributes = {
NSColor = "UIDeviceWhiteColorSpace 1 1";
}
title font = (null)

最佳答案

您可以访问导航栏的 subview 以获取标题和字体

for (UIView *sv in self.navigationController.navigationBar.subviews)
{
if (sv.subviews.count > 0 && [sv.subviews[0] isKindOfClass:[UILabel class]])
{
UILabel *lbl = (UILabel *)sv.subviews[0];
NSLog(@"%@",lbl.font);
break;
}
}

控制台输出

<UICTFont: 0xd8a3e50> font-family: "Helvetica-Light"; font-weight: normal; font-style: normal; font-size: 16.00pt

关于ios - 如何读取UINavigationController中标题的字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21924694/

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