gpt4 book ai didi

ios - 如何在 iOS 13 中使用 UINavigationBarAppearance

转载 作者:行者123 更新时间:2023-11-28 19:25:54 25 4
gpt4 key购买 nike

如何使用这个新对象来自定义 iOS 13 中的导航栏?我在 Objective-C 中尝试了以下代码,但它无法正常工作。当 View Controller 被推送或弹出到导航堆栈时,它只显示我的标题文本属性。

UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
appearance.titleTextAttributes = @{NSFontAttributeName: font};

这是该对象的文档。 https://developer.apple.com/documentation/uikit/uinavigationbarappearance?language=objc

最佳答案

仅仅创建一个 UINavigationBarAppearance 的实例是不够的。您实际上必须在 UINavigationBar 实例(或其外观代理)上设置它。

// Setup the nav bar appearance
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
appearance.titleTextAttributes = @{NSFontAttributeName: font};

// Apply it to a specific nav bar
someNavBarInstance.standardAppearance = appearance;
// There are also the compactAppearance and scrollEdgeAppearance properties that can be set as needed.

如果您希望对应用中的所有导航栏进行相同的自定义,请将其应用于 UINavigationBar.appearance 代理。

UINavigationBar.appearance.standardAppearance = appearance;

关于ios - 如何在 iOS 13 中使用 UINavigationBarAppearance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58102134/

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