您如何使用此新对象自定义iOS 13中的导航栏?我在Objective-C中尝试了以下代码,但无法正常工作。它仅在将视图控制器推入或弹出到导航堆栈时显示我的标题文本属性。
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;