滚动表格时,NavigationBar 的颜色会改变。

huangapple go评论58阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年2月27日 11:20:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576513.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定