如何使用此新对象自定义iOS 13中的导航栏?我在Objective-C中尝试了以下代码,但它不能正常工作。当视图控制器被推入或弹出到导航堆栈时,它只显示我的标题文本属性。
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
appearance.titleTextAttributes = @{NSFontAttributeName: font};以下是此对象的文档。https://developer.apple.com/documentation/uikit/uinavigationbarappearance?language=objc
发布于 2019-09-25 23:54:32
仅仅创建一个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;发布于 2020-04-28 17:01:14
对我来说,即使我正确地将外观设置为当前的UINavigationBar,它仍然不起作用。
我发现,如果您在已显示的UINavigationBar上设置更新的外观,则需要调用navigationBar?.setNeedsLayout()。
发布于 2020-04-10 21:21:54
在iOS13中,您需要在UINavigationBarAppearance对象上设置标题颜色,如下所示(Objective C版本):
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
appearance.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
self.navigationController.navigationBar.standardAppearance = appearance;
self.navigationController.navigationBar.scrollEdgeAppearance = appearance;https://stackoverflow.com/questions/58102134
复制相似问题