0

你好下午好社区,

我想知道是否有可能在 swiftui 中预先选择特定图像,因为它是在 collectionView 或 tabbar 中完成的。

我在下面留下我的代码:

struct HomeBaseScreenViewController: View {

@ObservedObject var homeViewModel = HomeBaseScreenViewModel()
@State var caseToDisplay:AnyView?
@State private var isSelectedIndex = false
@State var selectedItem = 0

private let columns =  [GridItem(.flexible())]
private let icons: Array<String> = ["house.fill","car.2.fill","cart.badge.plus","laptopcomputer"]

@ViewBuilder func displaySelectedForeground() -> some View{
    
}


var customTabBar:some View{
    
    ScrollView(.horizontal){
        LazyHGrid(rows: columns,alignment: .center,spacing:35) {
            ForEach(icons.indices, id: \.self) { index in
                
                 Image(systemName:icons[index])
                    .resizable()
                    .foregroundColor(.yellow)
                    .frame(width: 35, height: 35)
                    .padding()
                    .overlay(
                        Circle()
                        .stroke(Color.blueGrey, lineWidth: 2)
                        )
                    .onTapGesture {
                        caseToDisplay = homeViewModel.moveToNextView(icons[index])
                    }
        
            }
            
        
        }
        .padding([.leading])
    }
    .frame(height: 70)
    .background( Color.blueGrey)
    .cornerRadius(20)
    .clipShape(Capsule())
}

var body: some View {
    GeometryReader{ geometry in
        
        ZStack{
            caseToDisplay
            customTabBar
       
        }
        .frame( height: geometry.size.height)
        .background(Color.black)
        
    }
    
}
 }

我希望能够将背景更改为预先选择的图像,以便我可以选择默认选项。

4

0 回答 0