Swift/SwiftUI:背景图像遮挡图像和文本



当我使用这段代码时,背景工作得很好,但其他图像,文本和标题完全被它挡住了。

struct MainView: View {
var body: some View {
VStack(alignment: .leading, spacing: -4.0) {
Image("acdemo")
//background
.edgesIgnoringSafeArea(.all)
.blur(radius: /*@START_MENU_TOKEN@*/40.0/*@END_MENU_TOKEN@*/)


Image("acdemo")
.renderingMode(.original)
.resizable(capInsets: EdgeInsets(top: 0.0, leading: 0.0, bottom: 0.0, trailing: 0.0))
.aspectRatio(contentMode: .fit)
.frame(width: 300.0, alignment: .top)
.cornerRadius(/*@START_MENU_TOKEN@*/40.0/*@END_MENU_TOKEN@*/)
.shadow(radius: /*@START_MENU_TOKEN@*/4/*@END_MENU_TOKEN@*/)
Spacer()
.frame(height: 30)
Text("Title")
.font(.title)
.fontWeight(.bold)
.foregroundColor(Color.white)
.multilineTextAlignment(.leading)
.padding(.leading, 6.0)
.shadow(radius: /*@START_MENU_TOKEN@*/4/*@END_MENU_TOKEN@*/)
Text("Artist")
.font(.title)
.fontWeight(.regular)
.foregroundColor(Color.white)
.multilineTextAlignment(.leading)
.padding(.leading, 6.0)
.shadow(radius: /*@START_MENU_TOKEN@*/4/*@END_MENU_TOKEN@*/)
}

}
}

这可能是一个非常简单的修复,我对Swift非常陌生。

试一下:

struct MainView: View {
var body: some View {
ZStack {
Image("acdemo")
//background
.edgesIgnoringSafeArea(.all)
.blur(radius: /*@START_MENU_TOKEN@*/40.0/*@END_MENU_TOKEN@*/)
VStack(alignment: .leading, spacing: -4.0) {
Image("acdemo")
.renderingMode(.original)
.resizable(capInsets: EdgeInsets(top: 0.0, leading: 0.0, bottom: 0.0, trailing: 0.0))
.aspectRatio(contentMode: .fit)
.frame(width: 300.0, alignment: .top)
.cornerRadius(/*@START_MENU_TOKEN@*/40.0/*@END_MENU_TOKEN@*/)
.shadow(radius: /*@START_MENU_TOKEN@*/4/*@END_MENU_TOKEN@*/)
Spacer()
.frame(height: 30)
Text("Title")
.font(.title)
.fontWeight(.bold)
.foregroundColor(Color.white)
.multilineTextAlignment(.leading)
.padding(.leading, 6.0)
.shadow(radius: /*@START_MENU_TOKEN@*/4/*@END_MENU_TOKEN@*/)
Text("Artist")
.font(.title)
.fontWeight(.regular)
.foregroundColor(Color.white)
.multilineTextAlignment(.leading)
.padding(.leading, 6.0)
.shadow(radius: /*@START_MENU_TOKEN@*/4/*@END_MENU_TOKEN@*/)
}
}
}

}

相关内容

  • 没有找到相关文章

最新更新