swift 滚动表时,导航栏的颜色会发生变化

k5ifujac  于 2023-02-28  发布在  Swift
关注(0)|答案(1)|浏览(517)

TableView滚动时导航栏颜色发生变化。我不知道如何解决此问题。请告诉我。(UIKit)

fivyi3re

fivyi3re1#

我认为这是iOS 15+中导航栏的默认行为。为了防止这种情况,您可以在故事板中选择导航栏,在属性检查器中选择check Standard & Scroll Edge,然后在Standard AppearanceScroll Edge Appearances部分更改背景颜色,或者查看此图片:Storyboard configuration
如果你想用编程的方式来完成,你可以在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

相关问题