英文:
When scrolling the table, the color of the NavigationBar changes
问题
NavigationBar颜色在TableView滚动时发生变化。我不知道如何解决这个问题。请告诉我。(UIKit)
英文:
NavigationBar color changes when TableView scrolls. I don't know how to fix this problem. Tell me please.(UIKit)
答案1
得分: 1
我认为这是iOS 15+导航栏的默认行为。要防止这种情况,您可以在Storyboard中选择导航栏,然后在属性检查器中选择“标准和滚动边缘”,然后更改“标准外观”和“滚动边缘外观”部分的背景颜色,或查看此图片:
Storyboard配置
如果您想以编程方式执行此操作,可以在viewDidLoad
中调用以下代码:
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .blue
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance
如果您希望全局执行此操作,可以在AppDelegate中调用以下代码:
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .red
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
英文:
I think it's a default behavior for navigation bar in iOS 15+. To prevent this you can select navigation bar in storyboard and check Standard & Scroll Edge
in attribute inspector, then change the background color in Standard Appearance
and Scroll Edge Appearances
section or see this image:
Storyboard configuration
If you want to do it programatically you can call this code in viewDidLoad:
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .blue
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance
If you want to do it globally you can call this code in AppDelegate:
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .red
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论