SwiftUI:如何使列表中的矩形居中?

Pie*_*kel 1 swift swiftui

如何使列表中的矩形居中?我在我的代码中尝试了一些对齐方式,但遗憾的是它没有任何影响。这与列表的默认行为有关吗?

在此输入图像描述

这是我的代码:

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)
                        .font(.largeTitle)
                        .fontWeight(.semibold)
                        .foregroundColor(Color.white)
                        .multilineTextAlignment(.center)
                }
            }
        }.navigationBarTitle(Text("Binas"))
    }
    
}
init() {
    UITableView.appearance().separatorStyle = .none
    UITableViewCell.appearance().backgroundColor = UIColor(red: 225 / 255, green: 225 / 255, blue: 235 / 255, alpha: 1)
    UITableView.appearance().backgroundColor = UIColor(red: 225 / 255, green: 225 / 255, blue: 235 / 255, alpha: 1)
}
Run Code Online (Sandbox Code Playgroud)

}

Asp*_*eri 5

给 ZStack 行中的最大可用空间,例如

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)
        .font(.largeTitle)
        .fontWeight(.semibold)
        .foregroundColor(Color.white)
        .multilineTextAlignment(.center)
}
.frame(maxWidth: .infinity)      // << here !!
Run Code Online (Sandbox Code Playgroud)