如何将状态栏背景颜色更改为不同的颜色。我正在使用 NavigationView 和 ZStack。
例如,我希望绿色导航栏上方的白色区域为绿色。我怎样才能改变它?
我试过的
这是我的 NavigationBar 代码:
init() {
UINavigationBar.appearance().largeTitleTextAttributes = [
.foregroundColor : UIColor(#colorLiteral(red: 0.8745098039, green: 0.3411764706, blue: 0, alpha: 1))]
UINavigationBar.appearance().backgroundColor = UIColor(named: "backgroundColor")
}
Run Code Online (Sandbox Code Playgroud)
这是我的应用程序背景颜色代码:
var body: some View {
NavigationView {
ZStack {
Color("backgroundColor")
.edgesIgnoringSafeArea(.all)
}
.navigationBarTitle(Text("Agenda"))
}
}
}
Run Code Online (Sandbox Code Playgroud)
最后但并非最不重要的是我的场景委托代码:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let newAppearance = UINavigationBarAppearance()
newAppearance.configureWithOpaqueBackground()
newAppearance.backgroundColor = .black
newAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
UINavigationBar.appearance().standardAppearance = newAppearance
//Other code for displaying the first screen …Run Code Online (Sandbox Code Playgroud) 如何使列表中的矩形居中?我在我的代码中尝试了一些对齐方式,但遗憾的是它没有任何影响。这与列表的默认行为有关吗?
这是我的代码:
struct ContentView: View {
var sectiesList = [
Secties(name: "Algemeen", color: Color.overigPink),
Secties(name: "Natuurkunde", color: Color.natuurkundeBlue),
Secties(name: "Wiskunde", color: Color.wiskundeBrown),
Secties(name: "Scheikunde", color: Color.scheikundeRed),
Secties(name: "Biologie", color: Color.biologieGreen)
]
var body: some View {
NavigationView {
ZStack {
Color.offWhite
List(sectiesList, id: \.name) { secties in
ZStack(alignment: .center) {
RoundedRectangle(cornerRadius: 25)
.fill(secties.color)
.frame(width: UIScreen.screenWidth * 0.85, height: UIScreen.screenHeight * 0.13, alignment: .center)
.shadow(color: Color.black.opacity(0.2), radius: 10, x: 10, y: 10)
.shadow(color: Color.white.opacity(0.7), radius: 10, x: -5, y: -5)
Text(secties.name) …Run Code Online (Sandbox Code Playgroud)